Data Structures & AlgorithmsModerateFlipkart/Uber OA · placement
The array [1, 2, 3, 4, 5, 6, 7, 8] is rotated RIGHT by 3 positions and then LEFT by 2 positions. What is the final array?
- A. [3, 4, 5, 6, 7, 8, 1, 2]
- B. [6, 7, 8, 1, 2, 3, 4, 5]
- C. [2, 3, 4, 5, 6, 7, 8, 1]
- D. [8, 1, 2, 3, 4, 5, 6, 7]
Correct answer: D. [8, 1, 2, 3, 4, 5, 6, 7]
The net effect is a left rotation by (2 − 3) mod 8 = 7, so the array starts at element 8: [8, 1, 2, 3, 4, 5, 6, 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
- Kadane's algorithm runs on [4, 0, 8, −3, −2, −2, −3, 2, −6]. What is the maximum sum of a non-empty contiguous subarray?
- How many characters must be deleted in total from two strings so that they become anagrams of each other? What is printed? python from…
- What does this loop-counting code print? (Python) python n, c = 33, 0 i = 1 while i < n: j = i while j < n: c += 1 j = 2 i += 1 print(c)
- Evaluate an infix expression of single digits with two stacks (operands and operators, usual precedence, left-associative). What is…
- One Lomuto partition (pivot = LAST element; i marks the end of the 'less than pivot' region; when a[j] < pivot, increment i and swap a[i]…
- Insertion sort (ascending; shift larger elements right, one key comparison per inner-loop test, the loop stops at the first element ≤ the…