Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many integers from 1 to 100 inclusive are perfect squares or perfect cubes?
- A. 14
- B. 12
- C. 4
- D. 2
Correct answer: B. 12
Squares ≤ 100: 10; cubes: 4 (1, 8, 27, 64); both (sixth powers): 1 and 64. Inclusion–exclusion gives 10 + 4 − 2 = 12. Ignoring the overlap gives 14, 4 counts only the cubes and 2 only the overlap.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the minimum number of single-character replacements needed to make "abcdba" a palindrome?
- How many well-formed strings of 3 pairs of parentheses (length 6) exist?
- On a line with cells 1 to 10, a lamp at position p lights cells p-2 to p+2. Lamps are placed at positions 1, 4, 6, 9. Do they light every…
- The histogram heights [1, 3, 3, 2, 3] describe bars of width 1. What is the area of the largest rectangle that fits under the histogram?
- How many integers from 1 to 50 inclusive have exactly two 1-bits in binary and are even?
- Under the hash h(s) = sum of the character codes of s, how many of the 3-letter strings "abc", "cab", "bac", "xyz", "zyx" share their hash…