Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many distinct values v occur in [5, 1, 2, 3, 9, 10, 4] such that v + 1 also occurs in the array?
- A. 6
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
Put the values in a set and test each v for v + 1 membership. The values 1, 2, 3, 4 (successors up to 5) and 9 (successor 10) give five.
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
- Closed meeting intervals [1,3], [3,4], [2,5], [6,7] cannot share a room if they overlap even at one point. What is the minimum number of…
- How many inversions does the array [-3, -1, -2] have (pairs i < j with a[i] > a[j])?
- In "abcabdabc", how many positions i >= 1 start an occurrence of the prefix "abc" (the first three characters)?
- What is the sum of all integers from 1 to 50 inclusive that are coprime to 50?
- Let L be the length of the longest common subsequence of "ABCBDAB" and "BDCABA". How many different index-selections in "ABCBDAB" give a…
- What is the length of the longest common subsequence of "dbacabb" and its cyclic rotation by one position (the string with its first…