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?
- A. 101010
- B. 100101
- C. 10102
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many contiguous windows of length exactly 4 in 2 5 1 4 7 3 6 2 9 have DISTINCT elements AND a sum divisible by 3?
- How many contiguous subarrays of 0 1 2 0 1 2 have a sum between 3 and 5 inclusive?
- How many NON-EMPTY subsequences of 3 1 4 1 5 9 (position subsets read in order) are STRICTLY increasing?
- How many NON-EMPTY subsequences of 2 3 4 7 8 5 (position subsets read in order) alternate in parity, so that each chosen value has the…
- How many subsequences of EXACTLY three elements of 1 4 2 5 7 9 6 (position subsets read in order) form an arithmetic progression (the…
- How many NON-EMPTY subsequences of 2 5 3 8 6 1 (subsets chosen by position) have (maximum − minimum) exactly 3?