โœ๏ธ

Search in Rotated Sorted Array

Medium๐Ÿท๏ธ Binary search๐Ÿ“‚ Recursion, Sorting & Searching
๐Ÿงฉ The problem

A sorted array of distinct numbers was rotated (e.g. [0,1,2,4,5,6,7] โ†’ [4,5,6,7,0,1,2]). Return the index of the target or -1, in O(log n).

Examples

  • [4,5,6,7,0,1,2], 0 โ†’ 4

๐ŸŽฏ Aim for: O(log n) time

โœ๏ธ Write your solution

Pick a language, press Run to try it, then Run tests to check it against every test case โ€” just like a coding interview.

โ† All practice problems