CrackML by @ml.with.umang
Interview questions / Python & DSA
Python & DSA interview question

Search in Rotated Sorted Array

Find a target in a rotated sorted array with distinct values.

mediumcodingEvidence 66/1001 source reportTikTok

The 60-second answer

Use modified binary search: at each step identify which half is sorted and whether the target lies inside it. Target O(log n) time and O(1) space.

Build the answer in this order

1
Clarify constraints

Use modified binary search: at each step identify which half is sorted and whether the target lies inside it.

2
Choose the approach

Target O(log n) time and O(1) space.

3
Prove complexity

Call out edge cases such as no rotation, target absent, one element, and rotation at boundaries.

4
Test edge cases

Explain the invariant before coding, then dry-run a small case and state time/space complexity.

A useful interview mental model

This is the shape of a strong answer—not a script to memorize.

01Clarify
02Approach
03Implement
04Test
05Complexity

Senior-level signal

  • State the sorted-half invariant before updating pointers; it prevents branch mistakes.
  • If duplicates are allowed, explain why worst-case complexity can degrade to O(n).

What the interviewer is really testing

Problem decomposition, correctness, data-structure choice, complexity reasoning, and clean implementation under pressure.

Likely follow-up questions

Can you improve the time or space complexity?
Which edge case is most likely to break this solution?
How would you test this under interview time pressure?

Common weak-answer patterns

  • Starting to code before constraints are clear.
  • Giving complexity without explaining why it is correct.
  • Skipping adversarial and boundary cases.