Data Structures & AlgorithmsHardGATE CS · TCS NQT
What is the length of the longest contiguous subarray of [4, 3, 2, 6, 1, 5] whose sum is at most 10?
- A. 3
- B. 4
- C. 5
- D. 7
Correct answer: A. 3
All values are positive, so a two-pointer window that shrinks while the sum exceeds 10 finds the longest valid window.
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
- How many times does the pattern aab occur in the string aabaabaab, counting overlapping matches?
- How many pairs (a, b) with 1 <= a <= b <= 12 satisfy lcm(a, b) > 36?
- Treat [4, -1, 5, -6, 3] as circular. Over all contiguous circular windows of length 1 to 5, what is the maximum window sum?
- How many integers from 1 to 1000 inclusive have a decimal digit sum equal to 10?
- What is the length of the longest contiguous subarray of [2, 2, 1, 3, 1, 1, 2] whose sum is divisible by 4?
- How many arithmetic triples (x, x+d, x+2d) with d >= 1 consist entirely of values from [1, 2, 3, 5, 7, 9]?