Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
What is the sum of all integers from 1 to 100 inclusive that are divisible by neither 3 nor 7?
- A. 2849
- B. 3360
- C. 2842
- D. 3367
Correct answer: C. 2842
Inclusion-exclusion on sums: subtract the multiples of 3 and of 7, then add back the multiples of 21. Subtracting the multiples of 3 alone (the last option) forgets the multiples of 7.
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 windows of length 3 in [1, 2, 1, 2, 3, 3, 1] contain exactly two distinct values?
- What is the floor of the square root of the sum of [1000, 2500, 900]?
- How many indices i in "xyzxyzxyz" satisfy s[i] = s[i + 3]?
- A singly linked list holds 1..7. Using the slow/fast pointer method, the slow pointer reaches the middle node. How many nodes come after…
- What is the minimum number of elements to delete from [1, 1, 1, 2, 2, 2, 2, 3] so that every value appears at most twice?
- Group the values [1, 2, 4, 5, 6, 9, 10] so that consecutive sorted values with difference at most 1 share a group. How many groups result?