Data Structures & AlgorithmsHardCAT · TCS NQT
Problem: How many integers from 1 to 500 are NOT perfect squares and NOT perfect cubes?
- A. 471
- B. 473
- C. 478
- D. 27
Correct answer: B. 473
22 squares + 7 cubes − 2 sixth powers (1, 64) = 27 are a square or cube, so 500 − 27 = 473. Not removing the overlap gives 471, removing only squares gives 478, and 27 is the excluded count.
More Coding Interview Problems questions
- Problem: The dynamic array doubles its capacity whenever it is full, starting from capacity 1. After inserting 9 elements one by one, how…
- Problem: In a binary heap stored in an array with 1-based indexing, the array [1, 3, 2, 7, 4, 5, 6] is a valid min-heap. What is the sum…
- Problem: Vertices 0–5 form a graph with edges 0-1, 1-2, 2-3, 3-0 and 4-5. A BFS from vertex 0 gives each vertex a distance. What is the…
- Problem: A stack-sortable check is applied to the permutation [3, 1, 2]: elements are pushed in order and popped whenever the top equals…
- Problem: The array [5, 2, 8, 2, 9, 1, 5, 5] contains repeated values. How many distinct values appear exactly twice?
- Problem: What is the maximum sum of a subsequence of [4, −1, 2, 1] with no two adjacent elements chosen (the empty selection is not…