Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
What is the length of the longest contiguous subarray of [2, -3, 0, -1, 4, -2, 5, -1] whose product is strictly positive?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
Track the longest window since the last zero where the count of negatives is even, using the parity of negatives and the positions of zeros. Allowing an odd number of negatives, or ignoring zeros, changes the answer.
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
- Let P[0] = 0 and P[k] be the XOR of the first k elements of [3, 5, 6, 3, 1, 5, 2]. How many pairs of indices (i < j) among 0..7 have P[i]…
- In how many ways can the binary string "0110100110" be cut into one or more contiguous segments so that every segment contains equally…
- Among all arrangements reachable from [4, 2, 1, 3] by swapping ONE pair of adjacent elements (or by doing nothing), what is the minimum…
- What is the minimum number of single-character flips needed to make "1101001011" alternate (no two adjacent characters equal)?
- What is the maximum sum of a contiguous subarray of [3, -2, 7, 1, -5, 4, 8, -1, 2] whose length is between 2 and 4 inclusive?
- How many strings of length 5 over the alphabet {0, 1, 2} have a digit sum divisible by 3 (the sum of their digit values)?