Data Structures & AlgorithmsVery hardCodeforces Div2 B · ICPC regional
How many non-empty contiguous subarrays of [10, 5, 2, 6] have a product strictly less than 100?
- A. 9
- B. 6
- C. 12
- D. 8
Correct answer: D. 8
Products grow as the right end extends, so two pointers (or brute force on this small array) works. Including products equal to 100 is a common off-by-one.
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
- An LRU cache holds 3 keys. Requests arrive in the order 1, 2, 3, 1, 4, 2, 5, 1, 2, 3, 4, 5, and a request for an absent key is a miss that…
- Given the linked list 1 -> 2 -> ... -> 8, the list is reversed in consecutive groups of 3 (a final group with fewer than 3 nodes is left…
- A linked list has a tail of 3 nodes leading into a cycle of 5 nodes. A slow pointer advances 1 node per step and a fast pointer advances 2…
- How many index pairs i < j satisfy (a[i] + a[j]) mod 7 = 0 for the array [3, 4, 7, 10, 11, 14, 21, 5, 9]?
- How many index pairs i < j satisfy a[i] XOR a[j] = 6 for the array [1, 4, 7, 2, 5, 3, 6]?
- How many contiguous subarrays of [3, -1, 2, -2, 4, -3, 1] have sum exactly 2?