2 votes 2 votes Reply with solution @Arjun sir,@habibkhan,@vijaycs Algorithms algorithms divide-and-conquer + – Shubham Sharma 2 asked Feb 7, 2017 Shubham Sharma 2 1.1k views answer comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments vijaycs commented Feb 7, 2017 reply Follow Share using HASHING data-structure we can do it in O(n) ... 1 votes 1 votes Shubham Sharma 2 commented Feb 7, 2017 reply Follow Share i got it 0 votes 0 votes reboot commented Jan 13, 2021 reply Follow Share can be solved using counting sort. (Only partial logic of counting sort needed) 0 votes 0 votes Please log in or register to add a comment.
Best answer 6 votes 6 votes One possible way. Construct a count array such that count[m] = No of elements with value m // O(n) Convert count to a cumulative count array such that count[m] = No of elements upto and including m // O(k) Range Query[a,b] = count[b] - count[a-1] //assuming $b >= a$ Total preprocessing Time = O(n+k) code dd answered Feb 7, 2017 • selected Feb 7, 2017 by vijaycs dd comment Share Follow See 1 comment See all 1 1 comment reply srestha commented Feb 7, 2017 reply Follow Share cannot see code 1 votes 1 votes Please log in or register to add a comment.