Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many integers from 1 to 300 are divisible by 4 or 6 but not by 12?
- A. 75
- B. 100
- C. 125
- D. 50
Correct answer: A. 75
Multiples of 4 or 6: 75 + 50 − 25 = 100; removing the 25 multiples of 12 leaves 75. 100 forgets the exclusion, 125 skips inclusion-exclusion, and subtracting the 12s twice gives 50.
More Coding Interview Problems questions
- Problem: A list of numbers is [10, 4, 9, 7, 5, 12]. A "peak" is an element strictly greater than both of its neighbours (end elements have…
- Problem: The string "racecarxyz" is examined for palindromic substrings of length at least 5. How many such palindromic substrings are…
- Problem: The number of ways to arrange the letters of "LEVEL" so that the two E's are not adjacent is what value?
- Problem: Consider the sequence 1, 4, 9, 16, … of perfect squares. What is the smallest square that is greater than 500 and also ends in…
- Problem: How many 4-letter strings over {A, B, C} have no letter appearing more than twice?
- Problem: The binary tree with root 10, left child 5, right child 15, and 5 having right child 7, 15 having left child 12, is traversed in…