Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
How many integers n with 1 <= n <= 200 have both n and n + 2 prime?
- A. 16
- B. 1
- C. 15
- D. 46
Correct answer: C. 15
Test primality by trial division for n and n + 2; the twin prime pairs up to about 200 are counted by their lower element. Checking n and n + 1 (second option) finds only the pair (2, 3).
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 size 3 in [2, 9, 3, 4, 1, 1, 6] have a maximum strictly greater than the sum of the other two elements?
- From [7, 2, 9, 4, 6, 1], delete exactly one contiguous block of length 2. What is the smallest possible value of (max minus min) of the…
- How many integers from 1 to 50 inclusive have no two adjacent 1-bits in binary?
- Remove exactly two elements from [4, 1, 5, 2, 3] to maximise the sum of what remains. What is the maximum remaining sum?
- How many distinct two-character substrings occur in "mississippi"?
- Perform two operations on [8, 5, 3, 9]: each operation takes the current largest value x and replaces it with floor(x / 2). What is the…