- Introduction to Challenges
- Insertion Sort 1
- Insertion Sort Itself
- Correctness and the Loop Invariant
- Running Time
-
Counting Sort 1 - Simple Counting Sort
- Prepare for Full Counting Sort
- The Full Counting Sort
-
QuickSort1 - Simple Quick Sort
- Quick-Sort Advanced
- Quick Sort Running Time
Input Format for standard Sorting Challenges:
- t - the number of test cases
- s - the size of the array
- ar - the list of integers
Prepare for Full Counting Sort
In the previous challenge, it was easy to print all the integers in order, since you did not need to access the original list. Once you had the frequencies of each integer, you could just print each integer in order the correct number of times. However, if there is other data associated with an element, you will need to access the original element itself.
In the final counting sort challenge, you will need to print the data associated with each integer. This means you will go through the original array to get the data, and then use some “helper arrays” to determine where to place everything in a sorted array.
You will be given a list that contains both integers and strings. In this challenge you just care about the integers. For every value i from 0 to 99, can you output L, the number of elements that are less than or equal to i?
Input Format
- t - the number of test cases. t cases follow:
- n - the size of the list ar. n lines follow, each containing an integer x, and a string, s.
Output Format
Output L for all numbers from 0 to 99 (inclusive).
Getting the Input
Optional Java boilerplate is provided below which scans the input into Blob
s where each Blob contains a integer num
and a String string
. In this challenge, you just care about the num
of each Blob
.
Click for More
Challenge
For every value i from 0 to 99, can you output L, the number of elements that are less than or equal to i?
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
Rod
Nov 17, 2:29 PMReceived this runtime error.
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
Main is only scanning for integers but the input includes strings.
Learneroo
Nov 18, 12:37 PM@Rod, sorry, new code to scan the input has been added. You can click "Reset Code" to load it.