Data Structures & AlgorithmsModerateTCS Digital · Infosys SP
An equilibrium index i has (sum of elements left of i) = (sum of elements right of i), excluding a[i]. Which indices of [0, 9, 2, 3, 4, 2, 3, 5, −3] (0-based) are equilibrium indices?
- A. 2
- B. 3
- C. 4
- D. none
Correct answer: B. 3
Total = 25. Scan with a running left sum L: index i works when L = total − L − a[i]. That holds at 3.
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
- A stack is implemented with two queues where push is costly (new element goes into the empty queue, then everything else is moved behind…
- Daily prices are [15, 17, 19, 13, 20, 17, 38, 38, 40]. What is the maximum profit with at most ONE buy and one later sell, and with…
- Using a sliding window with a last-seen index map, what is the length of the longest substring of "dbdcccdcbaddad" with all characters…
- Two strings are isomorphic if characters can be replaced one-to-one to turn one into the other. Version A checks both directions; version…
- Swap every two adjacent nodes of a linked list by relinking (not by swapping values). What is printed? python def swappairs(h): d = p =…
- Count distinct values in every window of size k with a frequency map. What is printed? python from collections import Counter a, k = [3…