Sort by

recency

|

946 Discussions

|

  • + 0 comments
    function bigSorting(unsorted) {
      return unsorted.sort((a, b) => {
        if (a.length !== b.length) {
          return a.length - b.length;
        }
    
        for (let i = 0; i < a.length; i++) {
          if (a[i] !== b[i]) return a[i] - b[i];
        }
      });
    }
    
  • + 0 comments
    def bigSorting(unsorted):
        return sorted(unsorted, key=lambda x: (len(x), x))
    
  • + 0 comments

    python3

    def bigSorting(unsorted):
        # Write your code here
        lengths = { len(i) for i in unsorted }
        s = []
        
        for l in sorted(list(lengths)):
            t = filter(lambda x: len(x) == l, unsorted)
            s += sorted(t)
            
        return s
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/GAvltofMdYc

    vector<string> bigSorting(vector<string> u) {
        sort(u.begin(), u.end(), [](string l, string r){
            if(l.size() == r.size()) return l < r;
            return l.size() < r.size();
        });
        return u;
    }
    
  • + 0 comments

    Choosing the best sorting algorithm depends on factors like dataset size. For large datasets, the native sort() function is often the best choice. In JavaScript (V8 engine) and Python, it uses TimSort, a hybrid of Merge Sort and Insertion Sort. TimSort is efficient with large, partially sorted data, offering O(n log n) worst-case performance. It's a great option for BigSort tasks, providing both speed and stability.