The Full Counting Sort

Sort by

recency

|

723 Discussions

|

  • + 0 comments
    void countSort(vector<vector<string>> arr) {
        map<int, vector<string>> strmap;
        
        for(int i = 0; i<arr.size(); i++){
            string newc = i<arr.size()/2 ? "-" : arr[i][1];
             
            strmap[stoi(arr[i][0])].push_back(newc);
        }
        
        for(auto&[key, vector] : strmap){
            for(int k = 0; k<vector.size(); k++){
                cout<<vector[k]<<" ";
            }
        }
        
    }
    
  • + 0 comments

    My java Solution

    public static void countSort(List> arr) { int n = arr.size(); int middle = n / 2; StringBuilder sb = new StringBuilder(); Entry[] entries = new Entry[n];

        for (int i = 0; i < n; i++) {
            String key = arr.get(i).get(0);
            String value = (i < middle) ? "-" : arr.get(i).get(1);
            entries[i] = new Entry(key, value);
        }
    
        Arrays.sort(entries, Comparator.comparing(entry -> Integer.parseInt(entry.number)));
    
        for (Entry e : entries) {
            sb.append(e.letters).append(" ");
        }
    
        System.out.print(sb.toString());
    
    }
    
  • + 0 comments
    def countSort(arr):
        # Write your code here
        temp_arr = [[] for i in range(100)]
        
        n = len(arr)
        for i, (num, val) in enumerate(arr):
            new_val = "-" if i < (n // 2) else val
            temp_arr[num].append(new_val)
        result = []
        for i in temp_arr:
            result.extend(i)
        print(" ".join(result))
    
  • + 0 comments

    My python sollution

    def countSort(a):
        m_value = 0
        for i in range(len(a)):
            if i < len(a) // 2 :
                a[i][1] = '-'
            a[i][0] = int(a[i][0])
            m_value = max(m_value,a[i][0])
        sort = [[] for i in range(m_value+1)]
        for j in range(len(a)):
            sort[a[j][0]].append(a[j][1])
        result = []
        for i in sort :
            result.extend(i)
        print(' '.join(map(str,result)))
    
  • + 0 comments

    Here is problem solution in python java c++ c and javascript - https://programmingoneonone.com/hackerrank-the-full-couting-sort-problem-solution.html