Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for The Full Counting Sort in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To Algorithm
The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.
Advantages of Algorithms:
- It is easy to understand.
- Algorithm is a step-wise representation of a solution to a given problem.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.
Link for the Problem – The Full Counting Sort– Hacker Rank Solution
The Full Counting Sort– Hacker Rank Solution
Problem:
Use the counting sort to order a list of strings associated with integers. If two strings are associated with the same integer, they must be printed in their original order, i.e. your sorting algorithm should be stable. There is one other twist: strings in the first half of the array are to be replaced with the character -
(dash, ascii 45 decimal).
Insertion Sort and the simple version of Quicksort are stable, but the faster in-place version of Quicksort is not since it scrambles around elements while sorting.
Design your counting sort to be stable.
Example
The first two strings are replaced with ‘-‘. Since the maximum associated integer is , set up a helper array with at least two empty arrays as elements. The following shows the insertions into an array of three empty arrays.
i string converted list 0 [[],[],[]] 1 a - [[-],[],[]] 2 b - [[-],[-],[]] 3 c [[-,c],[-],[]] 4 d [[-,c],[-,d],[]]
The result is then printed: .
Function Description
Complete the countSort function in the editor below. It should construct and print the sorted strings.
countSort has the following parameter(s):
- string arr[n][2]: each arr[i] is comprised of two strings, x and s
Returns
– Print the finished array with each element separated by a single space.
Note: The first element of each , , must be cast as an integer to perform the sort.
Input Format
The first line contains , the number of integer/string pairs in the array .
Each of the next contains and , the integers (as strings) with their associated strings.
Constraints
is even
consists of characters in the range
Output Format
Print the strings in their correct order, space-separated on one line.
Sample Input
20 0 ab 6 cd 0 ef 6 gh 4 ij 0 ab 6 cd 0 ef 6 gh 0 ij 4 that 3 be 0 to 1 be 5 question 1 or 2 not 4 is 2 to 4 the
Sample Output
- - - - - to be or not to be - that is the question - - - -
Explanation
The correct order is shown below. In the array at the bottom, strings from the first half of the original array were replaced with dashes.
0 ab 0 ef 0 ab 0 ef 0 ij 0 to 1 be 1 or 2 not 2 to 3 be 4 ij 4 that 4 is 4 the 5 question 6 cd 6 gh 6 cd 6 gh
sorted = [['-', '-', '-', '-', '-', 'to'], ['be', 'or'], ['not', 'to'], ['be'], ['-', 'that', 'is', 'the'], ['question'], ['-', '-', '-', '-'], [], [], [], []]
The Full Counting Sort – Hacker Rank Solution
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); StringBuffer[] map = new StringBuffer[100]; for(int i = 0; i < 100; i++) { map[i] = new StringBuffer(); } for(int i = 0; i < n; i++) { StringTokenizer tok = new StringTokenizer(in.readLine()); int v = Integer.parseInt(tok.nextToken()); String s = tok.nextToken(); map[v].append(i < n / 2 ? "-" : s).append(" "); } for(int i = 0; i < 100; i++) { System.out.print(map[i]); } System.out.println(); } }
tadalafil 20mg canada tadalafil 40mg usa buy erection pills
After that, double-click the text in the template to modify
the name, tagline, details, data, etc.
cefadroxil 250mg pills order propecia 5mg online propecia pill
buy generic estradiol for sale order minipress for sale buy prazosin 1mg generic
buy metronidazole 400mg generic buy sulfamethoxazole buy keflex 125mg
buy generic vermox tadalis cost tadalafil 10mg drug
cost avanafil 100mg order avana 100mg generic purchase diclofenac online
buy nolvadex tablets order tamoxifen 20mg generic order cefuroxime 250mg pill
indomethacin 50mg cheap buy cefixime 200mg pills buy suprax without prescription
order trimox 250mg generic arimidex 1 mg cost order biaxin 500mg for sale
buy catapres 0.1 mg online cheap order meclizine 25mg tiotropium bromide 9mcg ca
suhagra 50mg brand order sildenafil 50mg sildenafil pill
minocycline 50mg usa buy pioglitazone 30mg generic actos 30mg ca
buy isotretinoin 40mg generic order generic amoxil 250mg zithromax 500mg generic
azithromycin 500mg over the counter gabapentin over the counter buy neurontin cheap
order cialis 40mg for sale buy tadalafil 10mg pills buy cialis online safely
ivermectin 0.2mg men’s ed pills buy deltasone 10mg sale
purchase lasix online vibra-tabs us order ventolin 4mg generic
levitra over the counter plaquenil order online generic plaquenil
buy ramipril without a prescription buy glimepiride 4mg pills etoricoxib 120mg tablet
vardenafil 10mg usa buy zanaflex sale hydroxychloroquine brand
asacol ca buy astelin sale buy generic irbesartan
benicar 20mg oral buy calan 120mg generic divalproex ca
coreg 6.25mg ca buy chloroquine cheap cost chloroquine
purchase digoxin generic micardis us buy molnunat online
naprosyn 250mg price prevacid generic lansoprazole 30mg drug
baricitinib pills baricitinib over the counter atorvastatin 40mg canada
albuterol 100mcg without prescription order pyridium 200mg pills order phenazopyridine 200 mg generic