Data Structures & AlgorithmsModerateTCS NQT · CAT
Problem: The numbers 1 to 20 are split into odd numbers and even numbers. What is the absolute difference between the sum of the odd numbers and the sum of the even numbers?
- A. 100
- B. 110
- C. 210
- D. 10
Correct answer: D. 10
Pair (1,2), (3,4), …, (19,20): each pair differs by 1, so the gap is 10 (110 − 100). 100 is the odd sum, 110 the even sum, and 210 the total.
More Coding Interview Problems questions
- Problem: A string of length 5 uses the letters x, y, z. How many such strings contain each of the three letters at least once?
- Problem: The array [5, 3, 8, 6, 2, 7] is processed by the partition step of quicksort with pivot = first element (5), using the…
- Problem: Starting with the number 100, subtract the square of the smallest prime factor of the current number each step (the number is…
- Problem: The string "xyzxyzxyz" is split into 3 equal blocks of length 3. The blocks are compared: how many pairs of blocks (i < j) are…
- Problem: From the list of integers [10, 15, 20, 25, 30], remove the elements that are divisible by 4 or by 6 (the rest remain in order)…
- Problem: The number 1729 is written in base 10. What is the sum of its digits in base 12, given as the digit sum of 1729 written in base 12?