A ring buffer of timestamps was sorted ascending, with no repeats, and then rotated right by some unknown k (0 <= k < n) when it wrapped. You receive the rotated array nums.
Write rotationAmount(nums) that returns k. Use O(log n) time.
Input: nums = [15,18,2,5,9] Output: 2
The sorted array [2, 5, 9, 15, 18] rotated right by 2 gives this. The smallest value is at index 2.
Input: nums = [1,3,5] Output: 0
Already sorted, so it wasn't rotated.
1 <= nums.length <= 10^5-10^9 <= nums[i] <= 10^9.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #84 How Far Was It Rotated. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.