Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many integers from 1 to 64 inclusive have a binary representation (without leading zeros) that reads the same forwards and backwards?
- A. 15
- B. 13
- C. 36
- D. 14
Correct answer: D. 14
Binary palindromes of length L: 2^(ceil(L/2) - 1) of them. Summing over lengths 1 to 6 gives 1+1+2+2+4+4 with 64 included as length 7 being not a palindrome.
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
- What is the minimum number of characters that must be inserted anywhere in "abcb" to make it a palindrome?
- How many windows of size 4 in [1, 2, 1, 3, 4, 2, 5, 6] contain four pairwise distinct values?
- What is the smallest positive integer n such that n! ends in exactly 10 trailing zeros?
- Items [1, 1, 1, 1, 2, 2, 3] must be placed into stacks of capacity 3 such that each stack holds only identical items. What is the minimum…
- How many index pairs i < j in [0, 1, 2, 3, 4] satisfy a[i] + a[j] = a[i] a[j]?
- Repeatedly remove adjacent equal characters from "abbaca" using a stack. How many characters are removed in total?