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. The Full Counting Sort
  5. Discussions

The Full Counting Sort

Problem
Submissions
Leaderboard
Discussions

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

  • hanamthai02
    4 months ago+ 0 comments
    def countSort(arr):
        # Write your code here
        # the number of element in the array_res is max(arr[:,0]) + 1
        length_arr_res = 0
        for i in arr:
            if int(i[0]) > int(length_arr_res):
                length_arr_res = int(i[0])
        arr_res = [[] for i in range(length_arr_res+1)]
        # find first half array and convert it to '-'.
        for i in range(len(arr)//2):
            arr_res[int(arr[i][0])].append('-')
        # add last half array
        for i in range(len(arr)//2,len(arr)):
            arr_res[int(arr[i][0])].append(arr[i][1])
        # print it out
        for i in arr_res:
            for j in i:
                print(j,end=' ')
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy