We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Sorting
- Big Sorting
- Discussions
Big Sorting
Big Sorting
Sort by
recency
|
950 Discussions
|
Please Login in order to post a comment
Can someone help me understand why my program, written in JavaScript programming language, failed some test cases in solving bigSort challenge?
First of all (or scenario 1), I solved the "bigSort challenge" with application of bubble sort algorithms:
function bigSort(unsorted) { const size = unsorted.length;
To my surprise, this fails test: test case 2, test case 7 and some others.
Secondly (or scenario 2), I modified the code with the language in built "sort()" method. I provided it with the callback compare function as follows:
Folks, kindly help me understand why some test cases failed, specifically test case 2 and 7 in the two scenarios.
Here is my c++ solution, you can watch the explanation here : https://youtu.be/GAvltofMdYc
def bigSorting(unsorted): # Write your code here
MERGE SORT IS still the fastest algorithm since o(n) complexity
this is insertion sort (0)^2 ` def compare(res, current): if len(res) == 0: res = [current] return res for idx, pip in enumerate(res): if pip >= current: rep = idx if rep<0: rep = 0 res.insert(rep, current) return res res.append(current) print("final", res) return res
def bigSorting(unsorted): # Write your code here res =[] for datas in unsorted: data = int(datas) res = compare(res,data) fix = [] for bub in res: fix.append(str(bub)) print(bub) return fix `
Python3, tried this way
B
But you can always do
return sorted(unsorted, key = lambda x: (len(x), x))