Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many integers from 1 to 100 inclusive are divisible by at least one of 3, 5 or 7?
- A. 56
- B. 55
- C. 47
- D. 46
Correct answer: B. 55
Inclusion-exclusion: 33 + 20 + 14 - 6 - 4 - 2 + 0 = 55 gives the count, while forgetting the pair-intersections overshoots. Using only 3 and 5 is a different set.
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 sum of lcm(a, b) over all unordered pairs of distinct positions in [2, 3, 4, 6]?
- How many non-empty subsequences of [2, 3, 5, 7] have a product strictly less than 50?
- In how many ways can [1, 2, 3, 0, 3] be cut into 3 non-empty contiguous parts such that all three parts have equal sum?
- What is the length of the longest contiguous subarray of [1, 5, 6, 2, 8, 3] whose maximum minus minimum is at most 3?
- Meetings occupy the half-open intervals [s, f) listed as (1,2), (3,4), (0,6), (5,7), (8,9), (5,9). Only one meeting may use the room at a…
- Children have greed factors [1, 2, 3] and cookies have sizes [1, 1]. A child is content if assigned a cookie of size at least their greed…