Solve range minimum query