We have to input integers into an array one bye one.While the process of input is going we can be asked to find the smallest numbers out of the top(greatest) 1/3rd of the the numbers,any number of times.
eg:
input 1
input 7
input 9
tell the number
input 21
input 8
input 5
tell the number
input 11
tell the number
output should be:
9
9
11
Explanation:
- till the first query the array would have numbers 1 7 9, so the top 1/3rd numbers would be 9.As their is only one number so its the smallest also.
- when second query is made array would look like
1 7 9 21 8 5
, so on sorting array would be:21 9 8 7 5 1
, top 1/3rd numbers would be 21 and 9. smallest of those will be 9 - in the final query array has
1 7 9 21 8 5 11
, on sorting21 11 9 8 7 5 1
top 1/3rd numbers would be 21 and 11. smallest of those is 11.
The total number of integers in the array can be 250000
My approach is to apply selection algorithm with partition but it is getting time limit exceeded.