Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many distinct sums appear over all non-empty contiguous subarrays of [2, 1, 3, 1]?
- A. 8
- B. 6
- C. 10
- D. 7
Correct answer: D. 7
Put every subarray sum into a set and count it; the positional count of 10 subarrays is not the same as the number of distinct values.
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
- Ropes of lengths 4, 3, 2 and 6 must be joined pairwise into one rope; joining costs the sum of the two lengths and you may join any two…
- How many distinct palindromic strings of length 3 occur as subsequences of "abcba"?
- How many unordered pairs of words in ["listen", "silent", "enlist", "google", "gogole", "cat", "act"] are anagrams of each other?
- Replace every element simultaneously by (a[i] + a[i-1]) mod 10, indices cyclic, on [1, 2, 3, 4]. What is the resulting array?
- Activities (start, finish) are [(1, 4), (3, 5), (0, 6), (5, 7), (3, 9), (5, 9), (6, 10), (8, 11), (8, 12), (2, 14), (12, 16)]. Two…
- Meetings (start, end) are [(0, 30), (5, 10), (15, 20), (25, 40), (35, 50), (45, 60), (50, 55)]. A room can host one meeting at a time, and…