Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: For the set {2, 3, 4, 6, 8, 9, 12}, how many pairs (x, y) with x < y have x dividing y?
- A. 10
- B. 17
- C. 15
- D. 21
Correct answer: A. 10
Pairs x < y with x | y: 2→4, 6, 8, 12; 3→6, 9, 12; 4→8, 12; 6→12, total 10. Counting x | x too gives 17, gcd > 1 gives 15, and 21 counts all pairs.
More Coding Interview Problems questions
- Problem: A bag contains 2 red, 3 green and 4 blue balls. How many ways are there to choose 3 balls so that all three have different colours?
- Problem: The string "abcdefghij" is read two letters at a time in pairs; each pair (xy) is replaced by the pair reversed (yx). What is the…
- Problem: The sum of the numbers in the sequence 1, 1+2, 1+2+3, …, up to 1+2+…+12 is what value?
- Problem: In the array [2, 4, 6, 8, 10], count the number of subarrays whose sum is divisible by 4.
- Problem: A stack-based bracket checker reads the string "([]{()})[" and reports the number of unmatched opening brackets at the end (0 if…
- Problem: An LRU cache of capacity 2 handles requests 1, 2, 1, 3, 2, 1, 4. Each request that is not cached causes a miss and evicts the…