Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many integers in [2, 20] are neither divisible by 2 nor by 3?
- A. 7
- B. 6
- C. 8
- D. 10
Correct answer: B. 6
The remaining numbers are 5, 7, 11, 13, 17 and 19, so the count is 6. The number 1 is excluded by the range starting at 2.
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
- How many division steps (modulo operations) does Euclid's algorithm perform on the pair (252, 105) before the remainder becomes 0?
- A binary search on the sorted array 1, 2, ..., 100 looks for 37 using mid = (lo + hi) // 2 with lo = 0 and hi = 99. How many comparisons…
- How many unordered index pairs i < j in the sorted array [1, 3, 4, 6, 8, 9, 11] satisfy a[i] + a[j] = 12?
- How many distinct non-empty substrings does the string aaaa have?
- An array has only positive integers and you need the longest contiguous subarray whose sum is at most K, with n up to 10^6. Which method…
- How many contiguous subarrays of [3, 1, 4, 1, 5, 9] have a prime sum?