Median Queries Hackerearth Solution