CONTENTS

Sorting and Searching Interview Patterns

A focused guide to sorting tricks, binary search boundaries, lower bound, rotated arrays, and interval sweeps.

May 29, 2026
42
A

Sorting and searching questions are usually about structure. Sorting creates order; binary search exploits order; interval sweeps preserve a compact active state.

What To Recognize

Problem ShapePatternPractice
Only 0, 1, 2 valuesThree pointersSort Colors
Next lexicographic orderPivot and suffix reverseNext Permutation
First/last target indexBoundary binary searchFirst and Last Position
Sorted matrixFlattened binary searchSearch a 2D Matrix

Boundary Rule

When binary search feels buggy, write the meaning of your boundary first: first index greater than or equal to target, first index greater than target, or last index less than target.

FAQs

Is sorting allowed in interviews?

Yes, but explain the cost and whether sorting changes any required original order.

Why do binary search bugs happen?

Most bugs come from not defining whether the search interval is closed or half-open.

Share this article

0 comments

Please login to comment.
No comments yet.