Data Structures & AlgorithmsVery hard
Take the values of 4 9 2 7 3 8 5 6 1 10 at the ODD 0-based indices (1, 3, 5, …) in order, forming a new sequence. What is the length of the longest strictly increasing contiguous run in that new sequence?
- A. 5
- B. 3
- C. 2
- D. 1
Correct answer: C. 2
Extract the subsequence at odd indices, then scan it for the longest run of consecutive strict increases. Counting the length of the subsequence or allowing repeats changes the answer.
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
- Split 8 3 5 1 9 2 7 4 into consecutive blocks of 4 (positions 0–3 and 4–7). For each block take (max − min), and add these two numbers…
- In 3 1 4 1 5 9 2 6 5 3 5 8, count how many positions hold a NEW strict prefix maximum (the element is strictly greater than every element…
- How many DISTINCT strings are produced by all cyclic rotations of "abcabc" (including the identity rotation)?
- How many inversions (pairs i < j with A[i] > A[j]) does 4 5 6 1 2 3 contain?
- Records are (letter, number): (b, 2), (a, 1), (c, 2), (a, 2), (b, 1), (c, 1). Apply a stable sort by LETTER first, then a stable sort by…
- For every window of length 3 in 9 2 7 4 1 8, sort the window and take its MIDDLE value. What is the largest of these middle values?