Data Structures & AlgorithmsVery hard

Among binary strings of length 6 that contain exactly three '1's and no two '1's adjacent, which one is lexicographically smallest?

  1. A. 101010
  2. B. 100101
  3. C. 10102
  4. D. 010101

Correct answer: D. 010101

Lexicographic minimality puts 0s as early as possible; enumerating the eight valid strings and taking the minimum gives the answer. Taking the maximum, the second smallest, or assuming the alternating pattern is best each give a different string.

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

Exams that ask this topic