Data Structures & AlgorithmsHardGATE CS · ICPC regional
How many contiguous subarrays of [2, 4, 8, 3, 6] have an LCM equal to their maximum element?
- A. 10
- B. 9
- C. 7
- D. 12
Correct answer: B. 9
The LCM of a set is at least the maximum, with equality exactly when every element divides the maximum. Checking divisibility by the maximum is a quick test.
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 ordered triples (i, j, k) of distinct indices in [2, 3, 5, 1, 4] satisfy a[k] = a[i] + a[j], counting each unordered pair {i, j}…
- What is the length of the longest prefix of the string ababbaba that is itself a palindrome?
- An LRU cache of capacity 2 receives the request sequence 2, 1, 2, 3, 1, 2. A request is a hit if its key is cached. How many hits occur?
- How many integers i with 1 <= i <= 50 have i i mod 10 = 9?
- How many integers in the range 1 to 100 are coprime to 30 (that is, gcd(x, 30) = 1)?
- How many pairs of distinct array positions i < j in [1, 2, 3, 4, 5, 6, 9] have a[i] a[j] divisible by 6?