Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: How many integers n with 1 ≤ n ≤ 100 have a binary representation that reads the same forwards and backwards?
- A. 18
- B. 22
- C. 19
- D. 50
Correct answer: C. 19
Binary palindromes up to 100 are 1, 3, 5, 7, 9, 15, 17, 21, 27, 31, 33, 45, 51, 63, 65, 73, 85, 93, 99: 19. Testing decimal palindromes instead gives 18, extending to 127 gives 22, and 50 counts all odd numbers (every binary palindrome is odd, but not conversely).
More Coding Interview Problems questions
- Problem: What is the sum of the smallest prime factors of the integers 2 through 30 (each integer contributes its smallest prime divisor)?
- Problem: How many positive divisors does the number 2^10 × 3^4 have?
- Problem: What are the last two decimal digits of 3^200?
- Problem: What is the maximum value of a XOR b over all pairs (a, b) taken from the array [3, 10, 5, 25, 2, 8] (a and b may be equal)?
- Problem: The minimum number of characters to delete from "(()))(" to make the parentheses balanced (every ( has a matching ) after it) is…
- Problem: Selection sort is applied to [4, 3, 2, 1] and the number of element moves (assignments into the array) is counted as one per…