Back to problems

Match Cyclic Shift to Descending Sequence

Algorithm · Ebay · Easy

You are given an array nums of length n that is a permutation of the integers 1, 2, ..., n. For a non‑negative integer t where $$0 \le t Input: nums = [3, 2, 1, 5, 4] Output: 2 Explanation: Shifting the last 2 elements (5 and 4) to the front turns [3, 2, 1, 5, 4] into [5, 4, 3, 2, 1], which is the descending sequence of length 5. Therefore t = 2. Example 2 Input: nums = [1, 4, 2, 3] Output: -1 Example 3 Input: nums = [1, 5, 4, 3, 2] Output: 4 Explanation: The last 4 elements…

Checking your access…