Data Structures & AlgorithmsModerateTCS NQT · counting
Problem: How many integers in [1, 100] are not perfect squares? Run the code.
Problem: How many integers in [1, 100] are not perfect squares? Run the code.
print(sum(1 for x in range(1, 101) if int(round(x ** 0.5)) ** 2 != x))What is printed?
- A. 89
- B. 91
- C. 90
- D. 10
Correct answer: C. 90
There are 10 perfect squares from 1 to 100 (1, 4, ..., 100), so 90 numbers are not squares.
More Coding Interview Problems questions
- Problem: How many inversions does the array [5, 1, 4, 2, 3] have? Run the code. python a = [5, 1, 4, 2, 3] print(sum(1 for i in…
- Problem: What is the greatest common divisor of 12, 18, 30 and 42? Run the code. python from math import gcd from functools import reduce…
- Problem: What is the worst-case time complexity of binary search for the first occurrence of a value in a sorted array that contains…
- Problem: Which algorithm constructs an Euler circuit of a connected graph whose vertices all have even degree in linear time?
- Problem: What is the time complexity of computing the Z-array of a string of length n?
- Problem: Which deterministic algorithm finds the global minimum cut of an undirected weighted graph with V vertices in O(V^3) time?