Data Structures & AlgorithmsHardGATE CS · competitive programming
Treat [5, −3, 5] as a circle. What is the maximum sum of a non-empty contiguous subarray, where the subarray may wrap around the end?
- A. 10
- B. 7
- C. 5
- D. 2
Correct answer: A. 10
Wrapping lets you take both 5s, at indices 2 and 0, for 10. Plain Kadane on the line gives 7 (the whole array), which misses the wrap.
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
- Ten people stand in a circle numbered 1 to 10. Counting from person 1, every 3rd person is eliminated and removed, and counting continues…
- The same rule, with every 3rd person eliminated, applies to n = 41 people. Who survives (1-based)?
- How many permutations of 1..5 can be produced by pushing 1, 2, 3, 4, 5 in order onto a stack and popping at any moment?
- How many pairs i < j in [2, 7, 3, 5, 8, 4] have A[i] + A[j] divisible by 3?
- How many non-empty contiguous subarrays of [4, 5, 0, 2, 3, 1] have a sum divisible by 5?
- Finding the k-th smallest element with a median-of-medians pivot is used as a deterministic selection method. What is its worst-case time…