Data Structures & AlgorithmsEasyAccenture · Cognizant coding round pattern

Problem: A ride app must repeatedly add drivers with ratings and remove the highest-rated driver, n = 10⁵ operations. Which data structure is best and why?

  1. A. A sorted array – O(1) insert
  2. B. A queue – FIFO gives the best driver
  3. C. A hash map – O(1) maximum lookup
  4. D. A max-heap (priority queue) – O(log n) insert and extract-max

Correct answer: D. A max-heap (priority queue) – O(log n) insert and extract-max

A heap keeps the maximum at the root with logarithmic updates. A sorted array needs O(n) shifting per insert, a queue ignores ratings, and a hash map has no ordering, so finding the maximum is O(n).

More Coding Interview Problems questions

Exams that ask this topic