Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Search a rotated list

    Search a rotated list

    Mediumbinary searcharray

    An ascending list of distinct values was rotated at an unknown point ([0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). Return the index of target or -1, in O(log n).

    Example 1

    Input:  nums = [4,5,6,7,0,1,2], target = 0
    Output: 4

    Example 2

    Input:  nums = [4,5,6,7,0,1,2], target = 3
    Output: -1

    Example 3

    Input:  nums = [1], target = 0
    Output: -1

    Constraints

    • 1 ≤ nums.length ≤ 5000
    • Values are distinct

    Submit checks your solution against 10 tests, including hidden ones.

    /**
     * @param {int[]} nums
     * @param {int} target
     * @return {int}
     */
    function searchRotated(nums, target) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.