GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.hackerrank.com — The Full Counting Sort | HackerRank 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. 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 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):
Returns 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 . Constraints Output Format Print the strings in their correct order, space-separated on one line. Sample Input Sample Output 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.
sorted = [['-', '-', '-', '-', '-', 'to'], ['be', 'or'], ['not', 'to'], ['be'], ['-', 'that', 'is', 'the'], ['question'], ['-', '-', '-', '-'], [], [], [], []] Cookie support is required to access HackerRankSeems like cookies are disabled on this browser, please enable them to open this website |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |