I have a list of sorted non-overlapping intervals (zero-based, half open), e.g.
{[0, 5), [10, 20), [35, 40)}
Let's say I have a point in one of the intervals (say, 3 in this case) and a step value of +10 (i.e. move right 10 positions). Is there an algorithm that can compute my final position in O(1) time? (EDIT: maybe I should say, something better than O(n))
Numbers not covered by the interval are considered nonexistent positions, so position 3 with step +10 on the above intervals would result in a final position of 19 (+1 moves my position to 4, then the remaining +9 starts from position 10 up to position 19). Another example is if we have position 15 as the start and a step value of -10, we would then have a final position of 0.
For simplicity's sake, we can also assume that the final position always ends in one of the intervals. We may or may not know from which interval we should start counting, however.
I can of course iterate over the interval list in O(n) time (n = number of intervals). But I feel like there should be a better way to attack this.
P.S. Does this problem have a name? This feels like it should have a proper name, but I'm not sure what it is.