Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: What is the number of integers in [1, 10000] that are perfect squares and also end in the digit 9? Run the code.
Problem: What is the number of integers in [1, 10000] that are perfect squares and also end in the digit 9? Run the code.
print(sum(1 for x in range(1, 10001) if int(round(x ** 0.5)) ** 2 == x and x % 10 == 9))What is printed?
- A. 20
- B. 10
- C. 100
- D. 1000
Correct answer: A. 20
A square ends in 9 only if its root ends in 3 or 7; roots 1..100 give 10 + 10 = 20. Counting only roots ending in 3 gives 10, 100 counts all squares, and 1000 counts all numbers ending in 9.
More Coding Interview Problems questions
- Problem: How many ways are there to split the string '1234' into two non-empty parts whose integer values are both divisible by 3? Run the…
- Problem: How many non-empty subsets of {1, 2, 3, 4, 5, 6, 7, 8} have a sum that is a multiple of 4? Run the code. python from itertools…
- Problem: What is the minimum number of operations to make the array [5, 1, 4] strictly increasing where one operation increments any…
- Problem: What is the number of integers in [1, 999] whose digit product is 0? Run the code. python print(sum(1 for x in range(1, 1000) if…
- Problem: How many distinct pairs (i < j) of [6, 10, 15, 21] have gcd(ai, aj) = 1? Run the code. python from math import gcd a = [6, 10…
- Problem: What is the smallest positive integer that is divisible by every integer from 1 to 12? Run the code. python from math import lcm…