I am implementing a DP-based range minimum query data structure and algorithm in Python 2.7. Any advice on algorithm time complexity improvements, code bugs or code style issues are appreciated.More information about range minimum query.from collections import defaultdictimport randomdef build_rmq(numbers):    rmq_map = defaultdict(int) # key: tuple of (start, end) index, value: min value    j = 0    while 2 ** j - 1 < len(numbers):        j += 1    j -= 1    # print j    for step in range(0,j+1):        for i in range(0, len(numbers)):            if step == 0:                rmq_map[(i,step)] = numbers[i]                continue            if i + 2 ** (step-1) < len(numbers):                rmq_map[(i,step)] = min(rmq_map[(i, step-1)], rmq_map[(i + 2 ** (step-1), step-1)])            else:                rmq_map[(i,step)] = rmq_map[(i, step-1)]    return rmq_mapdef rmq_query(start, end, rmq_map):    j = 0    while start + 2 ** j - 1 <= end:        j += 1    j -= 1    x = rmq_map[(start, j)]    y = rmq_map[(end + 1 - 2 ** j, j)]    return min(x,y)if __name__ == __main__:    numbers = [0,5,2,5,4,3,1,6,3]    rmq_map = build_rmq(numbers)    #print rmq_map    start = random.randint(0, len(numbers)-1)    end = random.randint(0, len(numbers)-1)    if start > end:        start, end = end, start    print start, end, numbers[start:end+1]    print rmq_query(start, end, rmq_map)
Dynamic programming based range minimum query
python;algorithm;python 2.7