Data Structures & AlgorithmsHard

A circular linked list holds the values 2 7 4 9 1 6 3 in order, with the last node linked back to the first. How many nodes are STRICTLY greater than both of their neighbours?

  1. A. 4
  2. B. 3
  3. C. 2
  4. D. 5

Correct answer: B. 3

Each node is compared with its predecessor and successor, and the last node's successor is the first node because the list is circular. Forgetting the wrap-around, using non-strict comparisons, or counting valleys instead gives other values.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic