I am trying to create a mapping, where we are given an integer n
, and also a bunch of intervals that map to random numbers.
e.g. n = 55, and say we have intervals: [1:3]->-2,[4:10]->-3,[11:25]->-4,[26:44]->-5,[45:66]->-6, etc.
Is it possible/how can I create a mapping that is constant time, so that for any given n, I can find the corresponding interval, then the correct mapping to the negative number?
My thoughts are to create a dictionary, with keys as the intervals, and the values as the negative number- however would this be constant time lookup for any given n?