The Full Counting Sort

Sort by

recency

|

721 Discussions

|

  • + 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

  • + 0 comments

    python solution

    def countSort(arr):
        n = len(arr)
        sort = [ [ ] for _ in range(n)]
        for i, pair in enumerate(arr):
            if i < n// 2:
                pair[1] = "-"
            sort[int(pair[0])].append(pair[1])
        
        print(" ".join([char for line in sort for char in line]))
    
  • + 0 comments

    public static void countSort(List> arr) { // Write your code here int cnt = arr.size(); int hc = cnt / 2;

        List<List<String>> sc = new ArrayList<>(cnt);
    
        for (int i = 0; i < cnt; i++) {
            sc.add(new ArrayList<>());
        }
    
        int i = 0;
        for (int j = 0; j < cnt; j++){
            int key = Integer.parseInt(arr.get(j).get(0));
            String vlu = arr.get(j).get(1);
    
            if(i<hc){
                vlu = "-";
            }
            sc.get(key).add(vlu);
            i++;
        };
    
        sc.forEach((t) -> {
            if(!t.isEmpty()){
              System.out.print(String.join(" ", t)+ " ");
            }
        });
    }