Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A string of length 4 over {0, 1} has an even number of 1s. How many such strings are palindromes?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
Palindromes of length 4 are determined by their first two characters, giving four candidates; of these, the ones with an even number of 1s are 0000, 0110, 1001 and 1111, which yields four strings.
More Coding Interview Problems questions
- Problem: The product 2^3 · 3^2 · 5^1 · 7^2 has how many positive divisors?
- Problem: For the array [1, 3, 5, 7, 9], how many subarrays have an average equal to 5?
- Problem: The string "aabbccdd" has all its letters doubled. How many substrings of length 2 consist of two identical letters?
- Problem: A 2×4 grid has a wall at (0,2) (row, column, 0-indexed); all other cells are open. Moves go up, down, left or right. What is the…
- Problem: The complete directed graph on 4 vertices has an arc in both directions between every pair of distinct vertices. How many…
- Problem: The path graph P4 has vertices 1–4 and edges 1-2, 2-3, 3-4. How many edges does its complement graph (on the same vertices…