Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: In how many ways can 100 be written as a sum of two perfect squares x² + y² with 0 ≤ x ≤ y (unordered, non-negative)?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
Count pairs with 0 ≤ x ≤ y and x² + y² = 100. The representations 0² + 10² and 6² + 8² are the ones this condition admits; ordered pairs would double the count except for symmetric cases.
More Coding Interview Problems questions
- Problem: How many prime numbers are there in the range 1 to 200 (inclusive)?
- Problem: Compute σ(360), the sum of all positive divisors of 360.
- Problem: The gas-station problem: gas = [1, 2, 3, 4, 5] and cost = [3, 4, 5, 1, 2] around a circular route of 5 stations, starting with an…
- Problem: Children with greed factors g = [1, 2, 3] and cookies s = [1, 1] (each child takes at most one cookie, and a cookie of size ≥ the…
- Problem: Balloons are shot with arrows that burst every balloon whose horizontal interval contains the arrow's x position. Intervals are…
- Problem: A stream of integers arrives: 4, 9, 1, 7, 8, 3, 6. After each arrival from the 2nd onwards, we report the 2nd largest value seen…