question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
largest-local-values-in-a-matrix
Simpler || Faster || Fully Explained || Beats 100 % C#
simpler-faster-fully-explained-beats-100-c4o1
Intuition\n Describe your first thoughts on how to solve this problem. \nSimply use for loops to iterate over the matrix, with limit as n-2 for outer loops and
priyasmb24
NORMAL
2024-05-12T04:04:38.695780+00:00
2024-05-12T04:06:57.594830+00:00
1,064
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply use for loops to iterate over the matrix, with limit as n-2 for outer loops and i+3, j+3 for inner loops\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nInput: grid = [[9,9,8,1],\n [5,6,2,6],\n...
2
0
['Array', 'Matrix', 'Python', 'Java', 'C#']
0
largest-local-values-in-a-matrix
Easy C++ Constant Space Solution | Beats 100 💯✅ | Max Pooling
easy-c-constant-space-solution-beats-100-mhh7
Intuition\n Describe your first thoughts on how to solve this problem. \n- We start by traversing each cell in the grid.\n- For each cell, we consider its surro
shobhitkushwaha1406
NORMAL
2024-05-12T02:45:36.817928+00:00
2024-05-12T02:45:36.817954+00:00
258
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- We start by traversing each cell in the grid.\n- For each cell, we consider its surrounding cells (including diagonals) to find the maximum value.\n- Updating each cell\'s value in-place ensures that we maintain the largest local value ...
2
0
['Array', 'Math', 'Matrix', 'C++']
2
largest-local-values-in-a-matrix
Fastest execution || beats 100% users with JAVA || C++ || PYTHON3 || TYPESCRIPT
fastest-execution-beats-100-users-with-j-lm2o
Approach\nIterate Through Grid\n\n# Complexity\n- Time complexity: O(n^2)\n\n- Space complexity: O(n^2)\n\n# Explanation\n1. Method Signature:\n\n- We start wit
SanketSawant18
NORMAL
2024-05-12T00:19:05.956845+00:00
2024-05-12T00:19:05.956883+00:00
595
false
# Approach\nIterate Through Grid\n\n# Complexity\n- Time complexity: O(n^2)\n\n- Space complexity: O(n^2)\n\n# Explanation\n1. **Method Signature:**\n\n- We start with the Solution class containing the largestLocal method. The method takes a 2D integer array grid as input and returns a 2D integer array as the result.\n...
2
0
['Array', 'Matrix', 'C++', 'Java', 'TypeScript', 'Python3']
1
largest-local-values-in-a-matrix
Fast and easy to understand solution - 2ms
fast-and-easy-to-understand-solution-2ms-tfj7
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. Calculates the size of the resulting box (excluding outer edges).\n2.
virhansda2302
NORMAL
2024-01-21T11:39:27.547888+00:00
2024-01-21T11:39:27.547952+00:00
287
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Calculates the size of the resulting box (excluding outer edges).\n2. Creates a new 2D array box to store the largest local values.\n3. Iterates through each cell of the box array:\n * Calls maxValue to find the larges...
2
0
['Array', 'Math', 'Matrix', 'Java']
1
largest-local-values-in-a-matrix
The Only C Solution
the-only-c-solution-by-nitianvineet-4vi3
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
nitianvineet
NORMAL
2023-05-08T18:11:02.715498+00:00
2023-05-08T18:11:02.715534+00:00
85
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['C']
1
largest-local-values-in-a-matrix
FASTEST way with JAVA, 2ms(beasts 99.5%)
fastest-way-with-java-2msbeasts-995-by-a-35ke
\n\n# Code\n\nclass Solution {\n public int[][] largestLocal(int[][] grid) {\n int n = grid.length;\n int[][] ret = new int[n-2][n-2];\n
amin_aziz
NORMAL
2023-04-12T08:06:40.776512+00:00
2023-04-12T08:06:40.776561+00:00
1,217
false
\n\n# Code\n```\nclass Solution {\n public int[][] largestLocal(int[][] grid) {\n int n = grid.length;\n int[][] ret = new int[n-2][n-2];\n for(int a = 0; a < n-2; a++){\n int[] first = grid[a];\n int[] second = grid[a+1];\n int[] third = grid[a+2];\n ...
2
0
['Java']
1
largest-local-values-in-a-matrix
Beats 87% | C++
beats-87-c-by-pathakjuhi-yev5
Please upvote <3\n\n\nclass Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n int n=grid.size();\n vector<v
pathakjuhi
NORMAL
2023-03-13T10:22:16.838894+00:00
2023-03-13T10:22:16.838929+00:00
246
false
Please upvote <3\n\n```\nclass Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n int n=grid.size();\n vector<vector<int>>res(n-2,vector<int>(n-2,0));\n for(int i=0;i<n-2;i+=1){\n for(int j=0;j<n-2;j+=1){\n int x=0;\n fo...
2
0
[]
0
largest-local-values-in-a-matrix
JAVA | 2 ms
java-2-ms-by-firdavs06-389p
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Firdavs06
NORMAL
2023-02-27T07:51:45.874565+00:00
2023-02-27T07:51:45.874615+00:00
915
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Java']
2
largest-local-values-in-a-matrix
📌 c++ solution ✔
c-solution-by-1911uttam-69mr
\nclass Solution {\npublic:\n int find(int i,int j,vector<vector<int>>& grid){\n int ans= 0;\n \n for(int ii=0;ii<3;ii++)\n f
1911Uttam
NORMAL
2023-02-13T06:14:31.409511+00:00
2023-02-13T06:14:31.409557+00:00
790
false
```\nclass Solution {\npublic:\n int find(int i,int j,vector<vector<int>>& grid){\n int ans= 0;\n \n for(int ii=0;ii<3;ii++)\n for(int jj=0;jj<3;jj++)\n ans= max(ans, grid[i+ii][j+jj]);\n \n return ans;\n }\n//-------------------------------------------...
2
0
['C', 'C++']
0
largest-local-values-in-a-matrix
Python two loops (max_pooling)
python-two-loops-max_pooling-by-inversio-x5d2
Intuition\n Describe your first thoughts on how to solve this problem. \nThis is more like max_pooling in deep learning.\n\n# Approach\n Describe your approach
inversion39
NORMAL
2022-12-27T03:36:27.029297+00:00
2022-12-27T03:36:27.029347+00:00
535
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is more like `max_pooling` in deep learning.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. output shape would be `mxm`, where `m=n-3+1`\n2. loop through the `grid` matrix, get max value for each `3x3` blo...
2
0
['Python3']
1
largest-local-values-in-a-matrix
PYTHON3 BEST
python3-best-by-gurugubelli_anil-z0bt
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Gurugubelli_Anil
NORMAL
2022-11-17T16:36:09.592037+00:00
2022-11-17T16:36:09.592078+00:00
1,157
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['Python3']
1
largest-local-values-in-a-matrix
C++ solution | 2 simple ways
c-solution-2-simple-ways-by-_kitish-szf3
Method -> 1\n\nclass Solution {\nprivate:\n int giveMax(vector<vector<int>>& v,int i,int j){\n return max({v[i][j],v[i+1][j],v[i+2][j],v[i][j+1],v[i+1
_kitish
NORMAL
2022-10-29T15:40:13.499202+00:00
2022-10-29T15:40:13.499250+00:00
555
false
**Method -> 1**\n```\nclass Solution {\nprivate:\n int giveMax(vector<vector<int>>& v,int i,int j){\n return max({v[i][j],v[i+1][j],v[i+2][j],v[i][j+1],v[i+1][j+1],v[i+2][j+1],v[i][j+2],v[i+1][j+2],v[i+2][j+2]});\n }\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) {\n int n...
2
0
[]
1
largest-local-values-in-a-matrix
Solution in JAVA
solution-in-java-by-coderkuldeep7733-8p8x
class Solution {\n \n \n public static int large(int i,int j,int arr[][]){\n int l=0;\n for(int row=i;row<i+3;row++){\n for(in
coderkuldeep7733
NORMAL
2022-10-21T13:45:48.005800+00:00
2022-10-21T13:45:48.005825+00:00
14
false
class Solution {\n \n \n public static int large(int i,int j,int arr[][]){\n int l=0;\n for(int row=i;row<i+3;row++){\n for(int col=j;col<j+3;col++){\n if(arr[row][col] > l)\n l =arr[row][col];\n }\n }\n return l;\n }\n \...
2
0
[]
0
largest-local-values-in-a-matrix
Easy
easy-by-sunakshi132-vw8j
\nclass Solution:\n def largestLocal(self, grid: List[List[int]]) -> List[List[int]]:\n l=len(grid)-2\n ans=[]\n for i in range(l):\n
sunakshi132
NORMAL
2022-10-12T15:42:30.118692+00:00
2022-10-12T15:42:30.118736+00:00
515
false
```\nclass Solution:\n def largestLocal(self, grid: List[List[int]]) -> List[List[int]]:\n l=len(grid)-2\n ans=[]\n for i in range(l):\n ans.append([0]*l)\n for i in range(l):\n for j in range(l):\n ans[i][j] = max(grid[i][j],grid[i][j+1],grid[i][j+2],...
2
0
['Python']
1
largest-local-values-in-a-matrix
c++ solution easy 😍
c-solution-easy-by-rohan_bhingare-y5ln
class Solution {\npublic:\n int findMax(vector>& grid , int i ,int j)\n {\n int maxi=INT_MIN;\n for(int x=i ; x<i+3 ; x++){\n for
Rohan_Bhingare
NORMAL
2022-09-26T12:50:27.113020+00:00
2022-09-26T12:50:27.113067+00:00
969
false
class Solution {\npublic:\n int findMax(vector<vector<int>>& grid , int i ,int j)\n {\n int maxi=INT_MIN;\n for(int x=i ; x<i+3 ; x++){\n for(int y=j ; y<j+3 ; y++)\n maxi=max(maxi , grid[x][y]);\n }\n return maxi;\n }\n \n \n \n \n vector<ve...
2
0
['C']
1
largest-local-values-in-a-matrix
c++ solution | Easy understanding | BruteForce
c-solution-easy-understanding-bruteforce-ieo9
\nclass Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) \n {\n vector<vector<int>>ans(grid.size()-2,vector<int>(g
akshat0610
NORMAL
2022-09-25T17:30:03.679474+00:00
2022-09-25T17:30:03.679515+00:00
358
false
```\nclass Solution {\npublic:\n vector<vector<int>> largestLocal(vector<vector<int>>& grid) \n {\n vector<vector<int>>ans(grid.size()-2,vector<int>(grid.size()-2));\n\n for(int i=0;i<(grid.size()-2);i++)\n {\n for(int j=0;j<(grid.size()-2);j++)\n {\n int ele=...
2
0
['C', 'C++']
1
largest-local-values-in-a-matrix
TypeScript solution: easy and short
typescript-solution-easy-and-short-by-ni-anal
\nfunction largestLocal(grid: number[][]): number[][] {\n let result: number[][] = new Array(grid.length - 2).fill(0).map(x => []);\n for (let i = 0; i <
Nina_Torgunakova
NORMAL
2022-09-18T04:34:04.341687+00:00
2022-09-18T04:34:04.341723+00:00
178
false
```\nfunction largestLocal(grid: number[][]): number[][] {\n let result: number[][] = new Array(grid.length - 2).fill(0).map(x => []);\n for (let i = 0; i < grid.length - 2; i++) {\n for (let k = 0; k < grid.length - 2; k++) {\n result[i][k] = Math.max(...grid.slice(i, i + 3).map(row => row.slic...
2
0
['TypeScript']
0
largest-local-values-in-a-matrix
✅ [Rust] 0 ms, functional-style efficient sliding windows (with detailed comments)
rust-0-ms-functional-style-efficient-sli-ijr5
This solution employs a functional-style approach with sliding windows to first compute maximum values for triples across rows, then across columns. It demonstr
stanislav-iablokov
NORMAL
2022-09-10T23:10:16.788493+00:00
2022-10-23T12:58:17.391662+00:00
142
false
This [solution](https://leetcode.com/submissions/detail/796636578/) employs a functional-style approach with sliding windows to first compute maximum values for triples across rows, then across columns. It demonstrated **0 ms runtime (100%)** and used **2.2 MB memory (66.34%)**. Detailed comments are provided.\n\n**IF ...
2
0
['Rust']
0
largest-local-values-in-a-matrix
c++ || easy
c-easy-by-niraj_1-gw2n
\nclass Solution {\npublic:\n int solve(int r,int c,vector<vector<int>>& grid){\n int maxi=0;\n for(int i=-1;i<=1;i++){\n for(int j=
niraj_1
NORMAL
2022-08-31T08:10:22.410624+00:00
2022-08-31T08:10:22.410656+00:00
235
false
```\nclass Solution {\npublic:\n int solve(int r,int c,vector<vector<int>>& grid){\n int maxi=0;\n for(int i=-1;i<=1;i++){\n for(int j=-1;j<=1;j++){\n int row=r+i,col=c+j;\n maxi=max(grid[row][col],maxi);\n }\n }\n return maxi;\n }\n ...
2
0
['C']
1
largest-local-values-in-a-matrix
C++ Easy and simple solution
c-easy-and-simple-solution-by-ayushluthr-zsk6
Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F\n\nin
ayushluthra62
NORMAL
2022-08-17T17:45:26.561426+00:00
2022-08-17T17:45:26.561476+00:00
169
false
***Guy\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that it motivate\'s me to create more better post like this \u270D\uFE0F***\n```\nint getMax(vector<vector<int>>&grid, int i,int j){\n int maxi=INT_MIN;\n for(int x=i;x<i+3;x++){\n for(int y=j;y<j+3;y++){\n ...
2
0
['C', 'C++']
0
sort-by
🍞🍞🍞 1 LINE | Full thorough explanation | ✅ bread
1-line-full-thorough-explanation-bread-b-wt75
Approach\nFor an array arr, if we call arr.sort(), it will automatically sort the array. However, JavaScript won\'t automatically sort correctly, since how we w
TheGElCOgecko
NORMAL
2023-06-11T07:30:01.135864+00:00
2023-08-13T00:35:18.229414+00:00
9,416
false
# Approach\nFor an array ```arr```, if we call ```arr.sort()```, it will automatically sort the array. However, JavaScript won\'t automatically sort correctly, since how we want the array to be sorted is not solely based on the value of each element, but rather the result of each element being inputted into a function....
104
0
['Array', 'Sorting', 'JavaScript']
4
sort-by
🤯 More than you ever wanted to know about this topic
more-than-you-ever-wanted-to-know-about-uax49
2724. Sort By\n\nView this Write-up on GitHub\n\n## Summary\n\nThere are two built-in functions we could use, either Array.prototype.sort or Array.prototype.toS
VehicleOfPuzzle
NORMAL
2024-09-05T06:20:51.112595+00:00
2024-09-05T06:20:51.112631+00:00
3,053
false
# 2724. Sort By\n\n[View this Write-up on GitHub](https://github.com/code-chronicles-code/leetcode-curriculum/blob/main/workspaces/javascript-leetcode-month/problems/2724-sort-by/solution.md)\n\n## Summary\n\nThere are two built-in functions we could use, either [`Array.prototype.sort`](https://developer.mozilla.org/en...
41
0
['TypeScript', 'JavaScript']
5
sort-by
Simple one line.
simple-one-line-by-cpcs-f5ge
\n# Code\n\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a)
cpcs
NORMAL
2023-06-07T06:20:16.649688+00:00
2023-06-07T06:20:16.649742+00:00
4,196
false
\n# Code\n```\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a) - fn(b));\n};\n```
14
0
['JavaScript']
1
sort-by
using merge sort / quick sort
using-merge-sort-quick-sort-by-simonapiz-8au5
Merge Sort\n\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */// merge sort\nvar sortBy = function(arr, fn) {\n const n = arr.lengt
SimonaPiz
NORMAL
2023-06-29T08:53:48.502661+00:00
2023-06-29T08:53:48.502688+00:00
930
false
# Merge Sort\n```\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */// merge sort\nvar sortBy = function(arr, fn) {\n const n = arr.length;\n // base case\n if (n == 1) return arr;\n\n // divide\n const mid = Math.floor(n/2);\n const arrLeft = arr.slice(0, mid); \n const arrRight = arr...
13
1
['Sorting', 'Merge Sort', 'JavaScript']
2
sort-by
🗓️ Daily LeetCoding Challenge Day 24|| 🔥 JS SOL
daily-leetcoding-challenge-day-24-js-sol-puzs
\n# Code\n\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a) - fn(b));\n};\n
DoaaOsamaK
NORMAL
2024-06-14T19:09:49.316448+00:00
2024-06-14T19:09:49.316479+00:00
1,722
false
\n# Code\n```\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a) - fn(b));\n};\n```
11
0
['JavaScript']
2
sort-by
Use quicksort instead of native sort function - surprise! it's faster
use-quicksort-instead-of-native-sort-fun-uk3z
Code\n\nfunction sortBy(arr: any[], fn: Function, left = 0, right = arr.length - 1): any[] {\n if (left >= right) {\n return;\n }\n\n const pivo
RedMonkez
NORMAL
2023-06-18T08:15:55.800871+00:00
2023-06-18T08:15:55.800888+00:00
1,019
false
# Code\n```\nfunction sortBy(arr: any[], fn: Function, left = 0, right = arr.length - 1): any[] {\n if (left >= right) {\n return;\n }\n\n const pivotIndex = partition(arr, fn, left, right);\n\n sortBy(arr, fn, left, pivotIndex - 1);\n sortBy(arr, fn, pivotIndex + 1, right);\n\n return arr;\n};...
5
0
['TypeScript']
2
sort-by
Very Easy Solution: 1 Line Of Code
very-easy-solution-1-line-of-code-by-nis-uc4c
Intuition\nThe sortBy function takes an array arr and a function fn as parameters. It is designed to sort the array in ascending order based on the values retur
nishantpriyadarshi60
NORMAL
2023-10-20T03:34:17.792866+00:00
2023-10-20T03:34:17.792897+00:00
1,280
false
# Intuition\nThe sortBy function takes an array arr and a function fn as parameters. It is designed to sort the array in ascending order based on the values returned by the function for each element. In other words, it allows you to sort an array based on a custom criterion defined by the function fn.\n\n# Approach:\nT...
4
0
['JavaScript']
0
sort-by
Single line JS with explanation (90% run time)
single-line-js-with-explanation-90-run-t-5vvu
\n# Approach\n Describe your approach to solving the problem. \nUsing sort function in JS. \n\n# Solution\n Describe your approach to solving the problem. \nArr
user4495rR
NORMAL
2023-07-06T05:32:59.708011+00:00
2023-07-06T05:32:59.708031+00:00
843
false
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsing sort function in JS. \n\n# Solution\n<!-- Describe your approach to solving the problem. -->\nArray.sort(compareFn) works in the following way:\ncompareFn = (a,b)=> {\n/* some logic that returns 0, 1 or -1 \n\n1. a and b are the two elements p...
4
0
['TypeScript']
0
sort-by
Beats 87.63%🥳One Simple line with explanation😉✅
beats-8763one-simple-line-with-explanati-n6hw
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ayaAshraf
NORMAL
2023-12-21T16:29:14.783516+00:00
2023-12-21T16:29:14.783553+00:00
375
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
0
['JavaScript']
0
sort-by
Easy Solution
easy-solution-by-mdgolamrabbani-l153
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
mdgolamrabbani
NORMAL
2023-09-06T17:02:22.189341+00:00
2023-09-06T17:02:22.189362+00:00
484
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
0
['JavaScript']
0
sort-by
Two solutions - Array.prototype.sort() with closure, and a Quicksort implementation.
two-solutions-arrayprototypesort-with-cl-9xtk
Intuition\nThe Javacript Array prototype offers a swap method that takes a comparison function, but it requires the function to take two inputs and then return
nigh_anxiety
NORMAL
2023-06-17T18:08:57.643819+00:00
2023-06-17T18:08:57.643838+00:00
1,571
false
# Intuition\nThe Javacript Array prototype offers a swap method that takes a comparison function, but it requires the function to take two inputs and then return -1 (a < b) , 0 (a == b) or 1 (a > b), so we can\'t just pass the provided `fn` variable into `Array.swap()`\n\n# Approach\nCreate a new swap function using `f...
3
0
['JavaScript']
0
sort-by
Easy and simple solution | one line Solution
easy-and-simple-solution-one-line-soluti-6pml
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Nitin_singh_000
NORMAL
2024-05-02T16:11:03.852800+00:00
2024-05-02T16:11:03.852833+00:00
806
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['JavaScript']
0
sort-by
✅ ✅ Simple TypeScript Solution with explanation ✅ ✅
simple-typescript-solution-with-explanat-j13g
\nWe have to return sorted array, so we simply use arrays method sort. But the values, that has to be sorted dependent on function "fn" from arguments. Because
arturKulish
NORMAL
2024-03-04T18:33:16.137720+00:00
2024-03-04T18:33:16.137750+00:00
765
false
\nWe have to return sorted array, so we simply use arrays method sort. But the values, that has to be sorted dependent on function "fn" from arguments. Because of that we have to run function inner and pass arguments "a" and "b". The functions return us values that we have to compare. So we do it and return result.\n\n...
2
0
['TypeScript']
0
sort-by
100 % Beats
100-beats-by-alokranjanjha10-nl6t
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
alokranjanjha10
NORMAL
2023-07-27T12:37:28.504700+00:00
2023-07-27T12:37:28.504720+00:00
1,151
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['JavaScript']
1
sort-by
1 line solution
1-line-solution-by-bikramghoshal6337-sc94
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
bikramghoshal6337
NORMAL
2023-07-26T17:12:25.878278+00:00
2023-07-26T17:12:25.878299+00:00
714
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['JavaScript']
0
sort-by
Very easy and simple solution in JS :)
very-easy-and-simple-solution-in-js-by-a-7mel
\n# Code\n\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n return arr.sort((a,b) => fn(a) -
AzamatAbduvohidov
NORMAL
2023-07-13T12:51:39.214350+00:00
2023-07-13T12:51:39.214371+00:00
980
false
\n# Code\n```\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n return arr.sort((a,b) => fn(a) - fn(b))\n};\n```
2
0
['JavaScript']
0
sort-by
JavaScript Solution
javascript-solution-by-motaharozzaman199-8icd
\n\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n return arr.sort((a,b)=>fn(a)-fn(b));\n
Motaharozzaman1996
NORMAL
2023-06-08T12:28:14.034009+00:00
2023-06-08T12:28:14.034049+00:00
2,207
false
\n```\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n return arr.sort((a,b)=>fn(a)-fn(b));\n \n};\n```
2
0
['JavaScript']
0
sort-by
✅ 🌟 JAVASCRIPT SOLUTION ||🔥 BEATS 100% PROOF🔥|| 💡 CONCISE CODE ✅ || 🧑‍💻 BEGINNER FRIENDLY
java-solution-beats-100-proof-concise-co-sfpt
Complexity Time complexity:O(nlogn) Space complexity:O(n) Code
Shyam_jee_
NORMAL
2025-03-27T17:59:29.832651+00:00
2025-03-28T19:39:44.609156+00:00
139
false
# Complexity - Time complexity:$$O(nlogn)$$ <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity:$$O(n)$$ <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```javascript [] /** * @param {Array} arr * @param {Function} fn * @return {Array} */ var sortBy = function(arr, fn) { ret...
1
0
['JavaScript']
0
sort-by
Quick sort implementation | beats 98%
quick-sort-implementation-beats-98-by-sh-cg5n
IntuitionWe need to sort an array based on a custom function fn. The function transforms each element, and we compare the transformed values to determine the or
sharqawycs
NORMAL
2025-03-04T09:07:37.387970+00:00
2025-03-04T09:07:37.387970+00:00
44
false
# Intuition We need to sort an array based on a custom function `fn`. The function transforms each element, and we compare the transformed values to determine the order. QuickSort is a good choice because it efficiently sorts in-place with an average time complexity of `O(n log n)`. # Approach 1. Copy the input array ...
1
0
['Sorting', 'Merge Sort', 'JavaScript']
0
sort-by
JavaScript
javascript-by-adchoudhary-e333
Code
adchoudhary
NORMAL
2025-03-01T07:42:06.193271+00:00
2025-03-01T07:42:06.193271+00:00
209
false
# Code ```javascript [] /** * @param {Array} arr * @param {Function} fn * @return {Array} */ var sortBy = function(arr, fn) { return arr.sort((a,b) => fn(a) - fn(b)) }; ```
1
0
['JavaScript']
0
sort-by
Comparator function || JS ||
comparator-function-js-by-ashish_ujjwal-26xg
Code
Ashish_Ujjwal
NORMAL
2025-02-22T07:35:02.694924+00:00
2025-02-22T07:35:02.694924+00:00
128
false
# Code ```javascript [] /** * @param {Array} arr * @param {Function} fn * @return {Array} */ var sortBy = function(arr, fn) { return arr.sort((a,b)=> fn(a)-fn(b)); }; // (a, b) => a-b; sort no. in ascending order // It should return a number where: // -> A negative value indicates thtat a should come before...
1
0
['JavaScript']
0
sort-by
BEAT 70+% || EASY TO UNDERSTAND SOLUTION || JS
beat-70-easy-to-understand-solution-js-b-5sej
IntuitionApproachComplexity Time complexity: Space complexity: Code
Siddarth9911
NORMAL
2025-01-28T16:23:15.573467+00:00
2025-01-28T16:23:15.573467+00:00
244
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
1
0
['JavaScript']
0
sort-by
Easy Explanation
easy-explanation-by-pratyushpanda91-hlhy
Explanation:Built-in Sort:The sort() function in JavaScript allows sorting elements based on a comparison function. The comparison function (a, b) => fn(a) - fn
pratyushpanda91
NORMAL
2025-01-24T04:04:55.139829+00:00
2025-01-24T04:04:55.139829+00:00
175
false
# Explanation: ### Built-in Sort: The sort() function in JavaScript allows sorting elements based on a comparison function. The comparison function (a, b) => fn(a) - fn(b) computes the difference between the results of fn applied to a and b. ### Behavior: If fn(a) < fn(b), the function returns a negative value, indic...
1
0
['JavaScript']
0
sort-by
Beats 96.11%‼ You also could do this!
sort-by-by-harryakbaram-zvxn
IntuitionWe can use the Array.sort and use the fn paramater to get the value that we want to compare.Approach This is ascending sort, so we expect element n is
harryakbaram
NORMAL
2024-12-19T06:45:11.920888+00:00
2024-12-19T06:54:42.091708+00:00
242
false
# Intuition We can use the Array.sort and use the `fn` paramater to get the value that we want to compare. # Approach - This is ascending sort, so we expect `element n` is lesser than `element n+1` by substract `element n` by `element n+1` in the body function of Array.sort. # Complexity - Time complexity: O(n) - Sp...
1
0
['JavaScript']
0
sort-by
99.75 Beats
9975-beats-by-nawaf-rayhan2-09gx
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Nawaf-Rayhan2
NORMAL
2024-08-03T13:44:42.117395+00:00
2024-08-03T13:44:42.117426+00:00
9
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['JavaScript']
1
sort-by
Beats 84.66% of users with JavaScript
beats-8466-of-users-with-javascript-by-r-lbaz
\n\n# Code\n\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a
rudrasaha305
NORMAL
2024-03-09T15:43:40.257227+00:00
2024-03-09T15:43:40.257249+00:00
518
false
\n\n# Code\n```\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a) - fn(b));\n};\n\n```
1
0
['JavaScript']
1
sort-by
Production grade TS
production-grade-ts-by-stuymedova-s45s
Code\n\nconst sortBy = <I>(arr: I[], fn: (item: I) => number): I[] => {\n return arr.sort((a, b) => fn(a) - fn(b));\n};\n\n
stuymedova
NORMAL
2024-02-13T17:11:44.124374+00:00
2024-08-22T06:11:07.925439+00:00
18
false
# Code\n```\nconst sortBy = <I>(arr: I[], fn: (item: I) => number): I[] => {\n return arr.sort((a, b) => fn(a) - fn(b));\n};\n\n```
1
0
['TypeScript']
0
sort-by
2724. Sort By - Space complexity: O(1)
2724-sort-by-space-complexity-o1-by-ngan-utjb
Intuition\nThe problem involves sorting an array based on the values returned by a given function. The goal is to achieve ascending order according to the funct
nganthudoan2001
NORMAL
2024-01-09T08:02:42.340791+00:00
2024-01-09T08:02:42.340821+00:00
1,147
false
# Intuition\nThe problem involves sorting an array based on the values returned by a given function. The goal is to achieve ascending order according to the function outputs.\n\n# Approach\nThe approach directly uses the `sort()` method on the input array, providing a custom comparison function. This comparison functio...
1
0
['JavaScript']
1
sort-by
2724. Sort By - Just 01 line - Beats 95.81% of users with JavaScript (Runtime)
2724-sort-by-just-01-line-beats-9581-of-6m8hg
Intuition\nThe problem requires sorting an array based on the values returned by a given function. The sorting should be done in ascending order according to th
nganthudoan2001
NORMAL
2024-01-09T08:01:32.466713+00:00
2024-01-09T08:01:32.466755+00:00
403
false
# Intuition\nThe problem requires sorting an array based on the values returned by a given function. The sorting should be done in ascending order according to the function outputs.\n\n# Approach\nThe approach involves creating a shallow copy of the input array using `slice()`. This is done to avoid modifying the origi...
1
0
['JavaScript']
2
sort-by
1 Line solution (O(n log n))
1-line-solution-on-log-n-by-strix_wl-4api
Complexity\n- Time complexity: O(n log n).\n\n# Code\n\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a) - fn(b))\n};\n
Strix_wl
NORMAL
2023-12-02T04:33:20.598760+00:00
2023-12-02T04:33:20.598788+00:00
402
false
# Complexity\n- Time complexity: O(n log n).\n\n# Code\n```\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a) - fn(b))\n};\n```
1
0
['JavaScript']
0
sort-by
sort by - solution in Quick Sort
sort-by-solution-in-quick-sort-by-velayu-1cm8
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
Velayutham25
NORMAL
2023-11-14T17:24:24.199230+00:00
2023-11-14T17:24:24.199266+00:00
41
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['JavaScript']
0
sort-by
Beats 98.06%of users with JavaScript
beats-9806of-users-with-javascript-by-po-618i
\n> ***var sortBy = function(arr, fn) {\n return arr.sort((a,b) => fn(a) > fn(b) ? 1 : -1);};***\n
PoetryOfCode
NORMAL
2023-11-11T04:05:10.494014+00:00
2023-11-11T04:05:10.494035+00:00
9
false
```\n> ***var sortBy = function(arr, fn) {\n return arr.sort((a,b) => fn(a) > fn(b) ? 1 : -1);};***\n```
1
0
['JavaScript']
0
sort-by
JavaScript Sort By
javascript-sort-by-by-samabdullaev-l045
Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to return a sorted array, where the sorting is based on the output of a given f
samabdullaev
NORMAL
2023-11-09T15:47:46.737374+00:00
2023-11-09T15:47:46.737395+00:00
10
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to return a sorted array, where the sorting is based on the output of a given function, which exclusively returns numbers, ensuring the sorted array is in ascending order according to the function\'s output.\n\n# Approach\n<!-- De...
1
0
['JavaScript']
0
sort-by
Merge Sort
merge-sort-by-shivam-agrahari-t92c
Approach\nusing mergesort algorithm\n\n# Complexity\n- Time complexity: nlog(n)\n\n- Space complexity: nlog(n)\n\n# Code\n/**\n * @param {Array} arr #- The inpu
shivam-agrahari
NORMAL
2023-09-16T05:58:02.104613+00:00
2023-09-16T05:58:43.738992+00:00
106
false
# Approach\nusing mergesort algorithm\n\n# Complexity\n- Time complexity: nlog(n)\n\n- Space complexity: nlog(n)\n\n# Code\n```/**\n * @param {Array} arr #- The input array to be sorted.\n * @param {Function} fn #- A custom comparison function used for sorting.\n * @return {Array} #- A new array containing the sorted e...
1
0
['Merge Sort', 'JavaScript']
0
sort-by
return arr.sort((a, b) => fn(a) - fn(b))
return-arrsorta-b-fna-fnb-by-pbelskiy-js3o
js\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a) - fn(b));\n};\n
pbelskiy
NORMAL
2023-06-27T10:44:58.236615+00:00
2023-06-27T10:44:58.236647+00:00
230
false
```js\nvar sortBy = function(arr, fn) {\n return arr.sort((a, b) => fn(a) - fn(b));\n};\n```
1
0
[]
0
sort-by
Easy One Line Solution || JavaScript 🎁🎁
easy-one-line-solution-javascript-by-del-qo6b
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
deleted_user
NORMAL
2023-06-07T08:54:25.720655+00:00
2023-06-07T08:54:25.720687+00:00
2,163
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['JavaScript']
2
sort-by
Sort By
sort-by-by-naeem_abd-pu70
IntuitionApproachComplexity Time complexity: Space complexity: Code
Naeem_ABD
NORMAL
2025-04-10T11:45:04.690818+00:00
2025-04-10T11:45:04.690818+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
2724. Sort By Solution
2724-sort-by-solution-by-runl4avdwj-vm0d
IntuitionThis problem is focused on custom sorting using higher-order functions. We are required to implement a utility function sortBy(arr, fn) that: Sorts an
runl4AVDwJ
NORMAL
2025-04-07T15:35:14.704836+00:00
2025-04-07T15:35:14.704836+00:00
3
false
# **Intuition** This problem is focused on **custom sorting using higher-order functions**. We are required to implement a utility function `sortBy(arr, fn)` that: - Sorts an array **based on a transformation** applied to each element using a callback function `fn`. - The goal is to allow **dynamic and flexible sor...
0
0
['JavaScript']
0
sort-by
array.prototype.solution
arrayprototypesolution-by-gvictorlo-b4ac
IntuitionSince it was not limited to being able to use native js functions, thinking about doing the sorting "from scratch" seemed very complex, especially sinc
GVictorLO
NORMAL
2025-04-07T03:22:14.404608+00:00
2025-04-07T03:22:14.404608+00:00
3
false
# Intuition Since it was not limited to being able to use native js functions, thinking about doing the sorting "from scratch" seemed very complex, especially since the array could be made up of objects, numbers, strings, etc. So it was more intuitive to use the js sort method approach. # Approach solution using array...
0
0
['TypeScript']
0
sort-by
Sort By
sort-by-by-shalinipaidimuddala-8el2
IntuitionApproachComplexity Time complexity: Space complexity: Code
ShaliniPaidimuddala
NORMAL
2025-03-25T08:59:00.078911+00:00
2025-03-25T08:59:00.078911+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
2724. Sort By
2724-sort-by-by-h3thal-i6vi
IntuitionApproachComplexity Time complexity: Space complexity: Code
H3thal
NORMAL
2025-03-24T18:27:53.094341+00:00
2025-03-24T18:27:53.094341+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Solution Sort By
solution-sort-by-by-aprydatko-239d
Code
aprydatko
NORMAL
2025-03-22T11:01:26.678132+00:00
2025-03-22T11:01:26.678132+00:00
2
false
# Code ```javascript [] /** * @param {Array} arr * @param {Function} fn * @return {Array} */ var sortBy = function(arr, fn) { return arr.sort((first, second ) => fn(first) > fn(second) ? 1 : -1) }; ```
0
0
['JavaScript']
0
sort-by
Simple solution
simple-solution-by-itziks00-27cl
Code
itziks00
NORMAL
2025-03-20T18:56:14.603091+00:00
2025-03-20T18:56:14.603091+00:00
3
false
# Code ```javascript [] /** * @param {Array} arr * @param {Function} fn * @return {Array} */ var sortBy = function(arr, fn) { arr.sort(function(a, b){ return fn(a) - fn(b) }) return arr }; ```
0
0
['JavaScript']
0
sort-by
85 m/s runtime
85-ms-runtime-by-lhcee3-s3eu
IntuitionThe problem requires sorting an array based on the values returned by a given function fn. Since fn only returns unique numbers for different elements,
lhcee3
NORMAL
2025-03-20T09:57:09.904672+00:00
2025-03-20T09:57:09.904672+00:00
3
false
# Intuition The problem requires sorting an array based on the values returned by a given function fn. Since fn only returns unique numbers for different elements, we can use a simple sorting algorithm that compares these numerical outputs. JavaScript’s built-in .sort() method provides an efficient way to achieve this....
0
0
['JavaScript']
0
sort-by
Sort Problem Solve
sort-problem-solve-by-ariyaneiasin02-qrw3
IntuitionApproachComplexity Time complexity: Space complexity: Code
ariyanEiasin02
NORMAL
2025-03-13T03:43:06.834024+00:00
2025-03-13T03:43:06.834024+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Simple Solution 100%
simple-solution-100-by-soumya15-n7x6
IntuitionApproachComplexity Time complexity: Space complexity: Code
Soumya15
NORMAL
2025-03-10T04:24:25.609254+00:00
2025-03-10T04:24:25.609254+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
1 Line of code.👉
1-line-of-code-by-tiy1orr5gx-ekam
IntuitionApproachComplexity Time complexity: Space complexity: Code
TiY1orr5Gx
NORMAL
2025-03-07T03:34:14.125358+00:00
2025-03-07T03:34:14.125358+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Lets go sorting!
lets-go-sorting-by-ecabigting-nvqr
IntuitionApproachComplexity Time complexity: Space complexity: Code
ecabigting
NORMAL
2025-03-05T07:09:50.829135+00:00
2025-03-05T07:09:50.829135+00:00
4
false
# Intuition # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```javascript [] /** * @param {Array} arr * @param {Function} fn *...
0
0
['JavaScript']
0
sort-by
Very simple with one line 🔥🔥
very-simple-with-one-line-by-abdullah_ua-ithk
IntuitionApproachComplexity Time complexity: Space complexity: Code
Abdullah_UA
NORMAL
2025-03-05T06:21:16.678175+00:00
2025-03-05T06:21:16.678175+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Efficient JavaScript solution
efficient-javascript-solution-by-jayanth-a8h3
IntuitionApproachComplexity Time complexity: Space complexity: Code
jayanth_br
NORMAL
2025-03-04T04:19:13.595836+00:00
2025-03-04T04:19:13.595836+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Solution
solution-by-aradhanadevi_jadeja-khww
Code
Aradhanadevi_Jadeja
NORMAL
2025-02-28T11:23:49.195166+00:00
2025-02-28T11:23:49.195166+00:00
3
false
# Code ```javascript [] /** * @param {Array} arr * @param {Function} fn * @return {Array} */ var sortBy = function(arr, fn) { return arr.sort((a, b) => fn(a) - fn(b)); }; console.log(sortBy([5, 4, 1, 2, 3], x => x)); console.log(sortBy([{x: 1}, {x: 0}, {x: -1}], d => d.x)); console.log(sortBy([[3, 4], [5, 2]...
0
0
['JavaScript']
0
sort-by
Sort By - 30 Days of JavaScript
sort-by-30-days-of-javascript-by-aleksan-7k63
IntuitionApproachComplexity Time complexity: Space complexity: Code
AleksanderP
NORMAL
2025-02-24T09:49:22.925792+00:00
2025-02-24T09:49:22.925792+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Best & Simple solution ever | 97 ms - Beats 99.94%
best-simple-solution-ever-97-ms-beats-99-ak56
Code
Mathinraj
NORMAL
2025-02-20T11:48:45.024356+00:00
2025-02-20T11:48:45.024356+00:00
3
false
# Code ```javascript [] var sortBy = function(arr, fn) { return arr.sort((a,b) => fn(a) - fn(b)) }; ```
0
0
['JavaScript']
0
sort-by
Simple Solution Easy to understand
simple-solution-easy-to-understand-by-en-7b3u
IntuitionApproachComplexity Time complexity: Space complexity: Code
eng-rehman
NORMAL
2025-02-19T05:48:37.485145+00:00
2025-02-19T05:48:37.485145+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
easy javascript solution
easy-javascript-solution-by-haneen_ep-ic17
IntuitionApproachComplexity Time complexity: Space complexity: Code
haneen_ep
NORMAL
2025-02-18T01:25:01.236489+00:00
2025-02-18T01:25:01.236489+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
one line output in JavaScript and typescript
one-line-output-in-javascript-and-typesc-743v
IntuitionApproachComplexity Time complexity: Space complexity: Code
Barath_Balasubramanian
NORMAL
2025-02-05T13:06:33.066156+00:00
2025-02-05T13:06:33.066156+00:00
9
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['TypeScript', 'JavaScript']
0
sort-by
Beat 91% | Easy JS solution
beat-91-easy-js-solution-by-nitinkumar-1-ld4a
Code
nitinkumar-19
NORMAL
2025-02-01T20:05:14.823466+00:00
2025-02-01T20:05:14.823466+00:00
7
false
# Code ```javascript [] /** * @param {Array} arr * @param {Function} fn * @return {Array} */ var sortBy = function(arr, fn) { return arr.sort((a,b)=>fn(a)-fn(b)); }; ```
0
0
['JavaScript']
0
sort-by
JS - using (sort function with compare function in it).
js-using-sort-function-with-compare-func-6xsp
IntuitionApproachComplexity Time complexity: Space complexity: Code
Manmohan_Choudhary
NORMAL
2025-01-30T17:46:59.427888+00:00
2025-01-30T17:46:59.427888+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
LS: #2724
ls-2724-by-jaalle-cbrt
IntuitionApproachComplexity Time complexity: Space complexity: Code
jaalle
NORMAL
2025-01-25T19:22:45.903383+00:00
2025-01-25T19:22:45.903383+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['TypeScript', 'JavaScript']
0
sort-by
Sort By Solution.
sort-by-solution-by-johanc12-8ss0
IntuitionJust use sort method by subtracting fn(a) - fn(b)Code
johanc12
NORMAL
2025-01-24T02:42:11.555295+00:00
2025-01-24T02:42:11.555295+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Just use sort method by subtracting `fn(a) - fn(b)` # Code ```javascript [] /** * @param {Array} arr * @param {Function} fn * @return {Array} */ var sortBy = function(arr, fn) { return arr.sort((a, b) => fn(a) - fn(b)); }; ```
0
0
['JavaScript']
0
sort-by
Runtime 143 ms Beats 6.31% & Memory 70.26 MB Beats 5.34%
runtime-143-ms-beats-631-memory-7026-mb-mnjwj
IntuitionThe sortBy function sorts an array of elements based on the return value of a user-provided function fn. I decided to use the Quick Sort algorithm to r
bekcodingaddict
NORMAL
2025-01-23T08:38:52.696963+00:00
2025-01-23T08:38:52.696963+00:00
4
false
# Intuition The sortBy function sorts an array of elements based on the return value of a user-provided function fn. I decided to use the Quick Sort algorithm to recursively partition the array into smaller sub-arrays. # Approach Base Case: If the input array has 0 or 1 element, it is already sorted, so return it. Pi...
0
0
['JavaScript']
0
sort-by
Simple Solution with explanation of the program and approach to solve the problem step by step
simple-solution-with-explanation-of-the-fplhn
IntuitionUnderstand the given condition and think the logic to the given problem and the return value.ApproachWe just have to return the sorted array.Program Br
Shashankpatelc
NORMAL
2025-01-21T04:58:57.841736+00:00
2025-01-21T04:58:57.841736+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Understand the given condition and think the logic to the given problem and the return value. - - - # Approach <!-- Describe your approach to solving the problem. --> We just have to return the sorted array. - - - # Program Breakdown ` arr`...
0
0
['JavaScript']
0
sort-by
One Line Solution
one-line-solution-by-kovilapuvivek-jxds
IntuitionApproachComplexity Time complexity: Space complexity: Code
KovilapuVivek
NORMAL
2025-01-17T16:25:42.744434+00:00
2025-01-17T16:25:42.744434+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Solution in Javascript with decent memory and space complexity
solution-in-javascript-with-decent-memor-r4y8
Complexity Time complexity: Sorting an array has a worst-case time complexity of 𝑂(nlogn), where n is the length of the array. Space complexity: Average case
Mradulesh_Morya
NORMAL
2025-01-17T13:39:10.821565+00:00
2025-01-17T13:39:10.821565+00:00
6
false
# Complexity - Time complexity: Sorting an array has a worst-case time complexity of 𝑂(nlogn), where n is the length of the array. - Space complexity: Average case: O(log n) # Code ```javascript [] /** * @param {Array} arr * @param {Function} fn * @return {Array} */ var sortBy = function(arr, fn) { return ...
0
0
['JavaScript']
0
sort-by
Sorting Array Using a Comparator Function
sorting-array-using-a-comparator-functio-44cp
IntuitionApproachComplexity Time complexity: Space complexity: Code
chris0403
NORMAL
2025-01-16T06:08:42.850294+00:00
2025-01-16T06:08:42.850294+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Easy approach 🔥🔥
easy-approach-by-rajasibi-wc3d
IntuitionApproachComplexity Time complexity: Space complexity: Code
RajaSibi
NORMAL
2025-01-16T05:51:30.746409+00:00
2025-01-16T05:51:30.746409+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Sort By simple solution ✅🚀
sort-by-simple-solution-by-its_me_1-ceqi
IntuitionSorting an array based on a computed value for each element is a common task. The sortBy function takes an array and a callback function (fn), which de
its_me_1
NORMAL
2025-01-14T02:11:57.627466+00:00
2025-01-14T02:11:57.627466+00:00
5
false
# Intuition Sorting an array based on a computed value for each element is a common task. - The `sortBy` function takes an array and a callback function (`fn`), which determines the sort key for each element. - The key idea is to compare elements based on the value returned by the callback function. # Approach - **Use...
0
0
['JavaScript']
0
sort-by
Javascript SortBy sollution
javascript-sortby-sollution-by-pankaj376-xing
IntuitionApproachComplexity Time complexity: Space complexity: Code
pankaj3765
NORMAL
2025-01-12T14:29:39.767398+00:00
2025-01-12T14:29:39.767398+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Sort
sort-by-wnascimento-a7mg
IntuitionApproachComplexity Time complexity: Space complexity: Code
wNascimento
NORMAL
2025-01-06T23:26:22.890298+00:00
2025-01-06T23:26:22.890298+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
2724. Sort By
2724-sort-by-by-g8xd0qpqty-0dff
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-06T17:41:09.709087+00:00
2025-01-06T17:41:09.709087+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
#2724: Sort By
2724-sort-by-by-dheeraj7321-fv95
IntuitionThe main idea behind solving this problem is to leverage JavaScript's built-in sort() method and customize it to sort elements based on a computed valu
Dheeraj7321
NORMAL
2025-01-03T11:50:32.249469+00:00
2025-01-03T11:50:32.249469+00:00
4
false
# Intuition The main idea behind solving this problem is to leverage JavaScript's built-in `sort()` method and customize it to sort elements based on a computed value using a function. The `sort()` method allows flexibility in defining sorting criteria by passing a comparator function. # Approach 1. The `sortBy` funct...
0
0
['JavaScript']
0
sort-by
Easy one line solutions
easy-one-line-solutions-by-virendangi123-0s1c
IntuitionApproachComplexity Time complexity: Space complexity: Code
Virendangi123
NORMAL
2024-12-24T12:56:47.750274+00:00
2024-12-24T12:56:47.750274+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['JavaScript']
0
sort-by
Sort By
sort-by-by-vitalii_baidak-7cy1
Code
vitalii_baidak
NORMAL
2024-12-20T08:03:49.933653+00:00
2024-12-20T08:03:49.933653+00:00
6
false
# Code ```typescript [] type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue }; type Fn = (value: JSONValue) => number function sortBy(arr: JSONValue[], fn: Fn): JSONValue[] { return arr.sort((a, b) => fn(a) - fn(b)); }; ```
0
0
['TypeScript']
0
sort-by
Basic approach ...!
basic-approach-by-vineeth_v_s-3h8l
IntuitionApproachComplexity Time complexity: Space complexity: Code
Vineeth_V_S
NORMAL
2024-12-18T05:13:42.286258+00:00
2024-12-18T05:13:42.286258+00:00
4
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['JavaScript']
0
sort-by
2724. Sort By
2724-sort-by-by-anikaleet-0qq2
IntuitionApproachExplanation: 1- Copying the Array:arr.slice() creates a shallow copy of the original array. This ensures the original array remains unchanged d
Anikaleet
NORMAL
2024-12-17T10:32:06.960301+00:00
2024-12-17T10:32:06.960301+00:00
5
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**Explanation:**\n1- Copying the Array:\n\n**arr.slice()** creates a shallow copy of the original array. This ensures the original array remains unchanged during the s...
0
0
['JavaScript']
0
sort-by
Sort By (JS)
sort-by-js-by-123malay-lb92
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
123Malay
NORMAL
2024-12-08T06:33:56.655089+00:00
2024-12-08T06:33:56.655134+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['JavaScript']
0
sort-by
Simple Way To Solve
simple-way-to-solve-by-anushanarc-pcrb
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
anushanarc
NORMAL
2024-12-04T12:18:44.124307+00:00
2024-12-04T12:18:44.124335+00:00
4
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['JavaScript']
0
sort-by
Js Easy
js-easy-by-hacker_bablu_123-qgt2
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires sorting an array based on a custom comparison function. The idea i
Hacker_Bablu_123
NORMAL
2024-12-02T17:17:04.645943+00:00
2024-12-02T17:17:04.645977+00:00
2
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires sorting an array based on a custom comparison function. The idea is to use JavaScript\'s built-in Array.prototype.sort() function and customize the comparison logic using the function fn provided as an argument.\n\n\n...
0
0
['JavaScript']
0
sort-by
One line
one-line-by-himanshusaini0345-5oc1
\n# Code\ntypescript []\ntype JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };\ntype Fn = (value: JSONValue) => number
himanshusaini0345
NORMAL
2024-11-28T11:23:04.821387+00:00
2024-11-28T11:23:04.821416+00:00
2
false
\n# Code\n```typescript []\ntype JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };\ntype Fn = (value: JSONValue) => number\n\nfunction sortBy(arr: JSONValue[], fn: Fn): JSONValue[] {\n return arr.sort((a,b) => fn(a) - fn(b))\n};\n```
0
0
['TypeScript']
0
sort-by
Easy and understandable solution.
easy-and-understandable-solution-by-azim-ph20
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
AzimovAsadbek
NORMAL
2024-11-18T19:27:06.969033+00:00
2024-11-18T19:27:06.969063+00:00
3
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['JavaScript']
0