Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many contiguous subarrays of [6, 10, 15, 4] have gcd exactly 1?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Once a subarray gcd reaches 1 every extension keeps 1, so the right end count for each start is easy to total. Brute force over the 10 subarrays confirms the count.
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
- A linked list holds 1..8 in order. Reverse the first group of 2 nodes, keep the next group of 2 as is, reverse the next, and so on. What…
- Exactly how many permutations of 1..5 can be sorted by a single stack (push and pop operations, output must be 1, 2, 3, 4, 5)?
- A queue holds 3, 1, 4, 2, 5 from front to back. You repeatedly look at the front element: if it is the next value needed (starting with…
- For windows of size 3 over [3, 1, 4, 2, 5, 1, 6, 0], how many windows have their maximum at the last position of the window (ties count as…
- Four unit-time jobs given as (deadline, profit) are (4, 20), (1, 10), (1, 40), (1, 30). Each job must finish by its deadline and only one…
- What is the length of the shortest contiguous subarray which, if sorted in place, makes the whole array [2, 6, 4, 8, 10, 9, 15] sorted?