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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Sorting
  4. Big Sorting
  5. Discussions

Big Sorting

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 856 Discussions, By:

recency

Please Login in order to post a comment

  • ADARSH_863
    2 weeks ago+ 0 comments

    C++

    bool myCmp(string s1, string s2) {
        return ((s1.size() == s2.size()) ? (s1 < s2) : (s1.size() < s2.size()));
    }
    vector<string> bigSorting(vector<string> unsorted) {
        sort(unsorted.begin(), unsorted.end(), myCmp);
        return unsorted;
    }
    
    0|
    Permalink
  • sngrisa
    3 weeks ago+ 0 comments

    Java 8:

    class Result implements Comparator<String>{
        
        public int compare(String str1, String str2){
            return (str1.length()==str2.length()) ? str1.compareTo(str2) : str1.length()-str2.length();
        }
    
        public static List<String> bigSorting(List<String> unsorted) {
            Collections.sort(unsorted, new Result());
            return unsorted;
        }
    }
    
    0|
    Permalink
  • jsr90pro
    3 weeks ago+ 0 comments

    Python:

    def bigSorting(unsorted):
        unsorted.sort(key=lambda s: (len(s), s))
        return(unsorted)
    		
    
    0|
    Permalink
  • honeybunny8040
    1 month ago+ 0 comments

    Want to use something simalar in JS to improve search of this website , basically I want functionaly of alphabetically arrange blog posts , which is not available by default in the theme I want to use, but when run in JS it has a lot of errors. I am not a professional developer my self but trying to solve this porblem on my own and practicing. sorting by numbers is possible by using this

     function bigSorting(unsorted) {
             return unsorted.sort((a, b) => (BigInt(a) > BigInt(b))? 0 : -1 );
        }
        bigSorting(unsorted).forEach(i=>console.log(i));
    
    -1|
    Permalink
  • omer7
    1 month ago+ 0 comments

    C# best solution 9/9

        public static List<string> bigSorting(List<string> unsorted)
        {
            unsorted.Sort((a,b)=>{
                if(a.Length!=b.Length) return a.Length-b.Length;
                int strLen = a.Length;
                for(int v = 0; v < strLen; v++){
                    if( a[v] == b[v] ) continue;
                    if( a[v] > b[v] ) return 1;
                    return -1;
                }
                return 0;
            });
            return unsorted;
        }
    		
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy