Data Structures & AlgorithmsHardCodeforces Div2 C · recursion
Problem: A string of length n is built using the operation 'append the reverse of the current string'. Starting with 'a', the length after k operations is 2^k. What is the complexity of an O(1)-per-character check of the k-th character by recursion on halves?
- A. O(n)
- B. O(n log n)
- C. O(1) per query with no structure
- D. O(log n)
Correct answer: D. O(log n)
Each recursion step halves the index range, so a query touches O(log n) levels. Generating the whole string takes O(n) and is the trap for large k.
More Coding Interview Problems questions
- Problem: Which statement about Dijkstra's algorithm using a binary heap with lazy deletion (pushing duplicate entries and skipping stale…
- Problem: What does the following print? python x = 5 print(x << 3 | x >> 1, x & 6, x ^ 3)
- Problem: For the string 'mississippi', what is the number of distinct substrings of length 2 that occur at least twice? Run the code…
- Problem: How many Armstrong numbers (numbers equal to the sum of their digits each raised to the power of the digit count) lie in [1…
- Problem: In how many ordered ways can 10 be written as a sum of parts from {1, 2, 3}, where the order of the parts matters? Run the code…
- Problem: How many subsets (including the empty subset) of [1, 2, 3] have XOR equal to 0? Run the code. python a = [1, 2, 3] print(sum(1…