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
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Counting Sort 1
  2. Discussions

Counting Sort 1

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • carlosiazzetti
    8 months ago+ 0 comments

    Easy Java solution:

    public static List<Integer> countingSort(List<Integer> arr) {
        //creates list with 100 elements filled with zeros
        List<Integer> res = new ArrayList<Integer>(Collections.nCopies(100, 0));
        for(Integer a : arr)
                res.set(a, res.get(a)+1);
        return res;
    }
    
    5|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature