Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: What is the LCM of the array [4, 6, 10, 15]?
- A. 3600
- B. 30
- C. 120
- D. 60
Correct answer: D. 60
Fold lcm(a, b) = a·b / gcd(a, b): lcm(4, 6) = 12, lcm(12, 10) = 60, lcm(60, 15) = 60. Multiplying all values gives 3600, treating 4 as contributing only one factor 2 gives 30, and multiplying lcm(4, 6) by 10 without dividing by the gcd gives 120.
More Coding Interview Problems questions
- Problem: Count the pairs (i, j) with i < j in the array [1, 2, ..., 10] whose sum is divisible by 4.
- Problem: Find the majority element (appearing more than half the time) of [2, 2, 1, 1, 1, 2, 2] using the Boyer–Moore voting algorithm…
- Problem: Kadane's algorithm finds the maximum sum of a non-empty contiguous subarray of [−2, 1, −3, 4, −1, 2, 1, −5, 4]. What is that…
- Problem: The array [1, 2, 3, 4, 5, 6, 7] is rotated right by 3 positions (the last 3 elements move to the front). What is the element at…
- Problem: Merging two sorted lists [1, 4, 7] and [2, 3, 8, 9] with the standard two-pointer merge, how many element comparisons are made in…
- Problem: In the expression print(232, (23)2) what are the two values printed, in order?