Loading
Loading
A sorted catalogue of distinct product codes was rotated by an unknown amount during a migration, so it now reads like the tail followed by the head.
Find the index of a target code, or -1 if it is absent. The search must be logarithmic.
codes = [4, 5, 6, 7, 0, 1, 2], target = 0mid=3 (7)left half [4..7] is sorted; 0 is not in itsearch rightmid=5 (1); left half [0,1] sorted, 0 is in itfoundindex 44Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(log n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Example 2
Example 3