So I just had a programming test for an interview and I consider myself a decent programmer, however I was unable to meet time constraints on the online test (and there was
The solution is to determine where the ranges overlap. The code needs to maintain a list of ranges, and as each input line is processed, the list must be updated. Assuming that there are only a small number of ranges compared with the number of items in the array, it will be much faster to process a table of ranges than naively update the array.
For example, lets's say that the array has ten million entries, and you were given two instructions
[0,5000000] 50
[4000000,6000000] 100
The naive solution will write 17 million entries in the array (10 million to initialize the array, and another 7 million to process the two instructions). But you can determine instantly that the max value is 150 because the two ranges overlap.