Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional
What is the smallest positive integer n such that 1 + 2 + ... + n is at least 500?
- A. 32
- B. 33
- C. 23
- D. 31
Correct answer: A. 32
Binary search on n with the closed form n(n+1)/2 finds the threshold: n = 31 gives 496, which is short, and n = 32 gives 528. Using n squared instead gives a different threshold.
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 elements to delete from [4, 9, 1, 6, 3, 8] so that the remaining elements have maximum minus minimum at most…
- How many proper borders (non-empty prefixes that are also suffixes, excluding the whole string) does "abacabab" have?
- Rotate "abcabd" one step to the left, then count the distinct substrings of length 3 in the rotated string.
- Four jobs need 5, 3, 4 and 1 units of time; a round-robin scheduler gives each job one unit per turn in queue order and removes finished…
- How many windows of size 3 in [1, 3, 2, 6, 4, 5, 1] have max minus min at most 2?
- How many integers from 1 to 50 inclusive have a digit sum that is divisible by 5?