Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT
How many indices i of [2, 2, 0, 2, 2] have the sum of the elements strictly to the left of i equal to the sum of the elements strictly to the right of i? (The element at i itself is excluded from both sides.)
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
Compare the left prefix with total minus left prefix minus a[i]; the element at i is in neither side. Requiring the left prefix to match the right side including a[i] is a different test.
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
- From the list 1 to 12, every node whose value is a perfect square (1, 4, 9) is deleted. What is the sum of the remaining values?
- Process [5, 3, 6, 2, 7, 1] with a stack: before each push, pop every element that is greater than or equal to the new value. How many…
- How many contiguous subarrays of [1, 2, 3, 4, 6, 2] have a product exactly equal to 12?
- How many index pairs i < j in [1, 2, 3, 4, 5, 6, 7, 8] have equal parity and a[i] + a[j] <= 10?
- What is the length of the longest substring of aabbbcca in which every letter occurs at most twice?
- How many palindromic substrings of length 3 or more does racecar contain (counted by position)?