Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

Hackerrank The Full Couting Sort problem solution

YASH PAL, 31 July 202430 November 2025

In this Hackerrank The Full Counting Sort problem we have given a list of strings associated with integers. we need to sort the list and print the values in sorted order.

Hackerrank The Full Couting Sort problem solution

Problem solution in Python programming.

import collections

def tc(n, arr):
    d = collections.defaultdict(list)
    for i in range(n):
        k,v = arr[i].split()
        if i < n//2:
            d[int(k)].append("-")
        else:
            d[int(k)].append(v)
    od = collections.OrderedDict(sorted(d.items()))
    print(" ".join([" ".join(l) for l in od.values()]))

n = int(input())
arr = []
for _ in range(n):
    arr.append(input())
tc(n,arr)

Problem solution in Java Programming.

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int entries = scanner.nextInt();
        StringBuilder[] freqs = new StringBuilder[100];
        for (int i = 0; i < entries; i++) {
            int idx = scanner.nextInt();
            if (i < entries / 2) {
                freqs[idx] = freqs[idx] == null ? new StringBuilder("-")
                                                : freqs[idx].append(" -");
                scanner.next();
            } else {
                freqs[idx] = freqs[idx] == null ? new StringBuilder(scanner.next()) 
                                                : freqs[idx].append(" ").append(scanner.next());
            }
        }
        for (int i = 0; i < freqs.length; i++) {
            if (freqs[i] != null) {
                System.out.print(freqs[i].toString());
                System.out.print(" ");
            }
        }
        System.out.println();
    }
    
    
}

Problem solution in C++ programming.

#include <cstdio>
#include <iostream>
#include <vector>
#define MAX 1000001

using namespace std;

int num;
vector<int> cnt[101];
string name[MAX];
int val[MAX];
int order[MAX];

int main(){
    cin >> num;
    int stop = num/2;
    int temp1;
    string temp2;
    for(int x = 0;x<num;x++){
        cin >> temp1 >> temp2;
        val[x] = temp1;
        name[x] = temp2;
        cnt[temp1].push_back(x);
    }
    for(int x = 0;x<100;x++){
        for(vector<int>::iterator it = cnt[x].begin();it!=cnt[x].end();++it){
            if((*it)<stop) cout << "- ";
            else cout << name[*it] << " ";
        }
    }

    return 0;
}

Problem solution in C programming.

#include <stdio.h>
#include <string.h>

#define MAXN 1000000
#define MAXNUM 100
#define MAXSTR 10

int main() {
    
    long i, j, n, num[MAXN];
    static char str[MAXN/2][MAXSTR];
    scanf("%ld", &n);
    
    for ( i = 0; i < n/2; i++ ) {
        scanf("%ld", &num[i]);
        scanf("%*s");
    }
    
    for ( i = n/2; i < n; i++ ) {
        scanf("%ld", &num[i]);
        scanf("%s", str[i-n/2]);
    }
    
    for ( i = 0; i < MAXNUM; i++ ) {
        for ( j = 0; j < n/2; j++ ) {
            if ( num[j] == i ) {
                printf("- ");
            }
        }
        for ( j = n/2; j < n; j++ ) {
            if ( num[j] == i ) {
                printf("%s ", str[j-n/2]);
            }
        }
    }
    
    return 0;
}

Problem solution in JavaScript programming.

function processData(input) {
    //Enter your code here
    var ar = input.split('n');
    var n = parseInt(ar.shift(), 10);
    var sorted = {}
    for(var i = 0; i < n; i++) {
        var space = ar[i].indexOf(' ');
        var pos = parseInt(ar[i].substr(0, space), 10);
        var chars = i < n/2 ? '-' : ar[i].substr(space + 1);
        sorted[pos] = (sorted[pos] || []);
        sorted[pos].push(chars);
    }
    var out = []
    for(key in sorted)
        out.push(sorted[key].join(' '));
    console.log(out.join(' '));
} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

Algorithms coding problems solutions AlgorithmsHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes