For example, lets say I have an array with the integers:
1 3 4 9 10
I want to find the number of elements between 1 and 9 (inclusive), so it should return 4 (as there are 4 integers [1,3,4,9] that are between one and nine inclusive).
One way I thought about doing this was to first place each integer J in the Jth position of the array so queries of whether the integer exists can be done in constant time. Then you can simply go through the range and check whether each number exists, but this takes too long for large numbers.
What is the fastest way to do it?