Skip to main content

Any software role

Coding problem: Search a Rotated List. A list of distinct integers was sorted in increasing order and then rotated: some prefix was moved to the end, so `[1, 3, 5, 8, 9]` might have become `[8, 9, 1, 3, 5]`. Given the rotated list `nums` and an integer `target`, return the index of `target` in `nums`, or `-1` if it isn't there.

TechnicalMid levelTests: Problem solving
Drill this questionCreate a free account to answer out loud with Ava and get feedback.

What the interviewer is looking for

  • What a strong solution looks like: a modified binary search — at each step one of [lo..mid] and [mid..hi] is sorted; check whether target lies inside the sorted half's range and discard the other half. O(log n) time, O(1) space. Alternative: binary search for the rotation point, then an ordinary binary search on the right part.
  • Think aloud. Interviewers are judging how you reason, not only the final code.
  • Be ready for: What if values can repeat (worst case becomes O(n) — why)? Find the smallest element or the rotation amount. How would you test this thoroughly (compare with a linear search on random rotations)?

A structure to follow: Clarify, plan, code, test, analyse

  1. Step 1

    Clarify

    Restate the problem, ask about empty input, duplicates and size limits, and agree on one example.

  2. Step 2

    Plan

    Say the simple approach first and its cost, then the better one. Explain why before you type.

  3. Step 3

    Code

    Write small named steps and talk through each. A clear solution beats a clever one.

  4. Step 4

    Test

    Walk your own example through the code, then an edge case. Fix what you find calmly.

  5. Step 5

    Analyse

    State time and space cost in plain words and say what you would change for much larger input.

This is guidance on shape, not a script. Use your own real experience and facts; never invent details to fill a gap. See the STAR guide and answer frameworks.

Common slips

  • Starting to code before agreeing what the answer must be.
  • Going silent when stuck instead of saying what you are trying.
  • Never running your own example through the code.

How to practise it

Solve it once in the editor without hints, then explain your solution aloud in under two minutes.

Browse all questions

Coding problem: Search a Rotated List. A list of distinct integers was sorted in increa... | How to answer