Skip to content

Interview question · Binary search

Search a 2D Matrix

Search a 2D Matrix is a Medium question that uses the binary search pattern. PrepKit files it under Binary search.

PrepKit lists the title and a link. The problem statement stays on the original site.

Checking your saved items

Copyright and correction requests

Source content: English

Key facts

Topic
Binary search
Pattern
binary search
Difficulty
Medium
Appears in
NeetCode 150
Website
leetcode.com
License
MIT License

How to use it

  1. Read the problem on the original site.
  2. Try it on your own before you look at hints or solutions.
  3. Then work through a related question with the same pattern.

About the Binary search pattern

PrepKit study notes. PrepKit editors wrote these as general advice. They are not taken from the problem or from any published solution.

What it is
Halving a sorted search space at each step to find a value or a boundary in logarithmic time.
How to recognize it
The input is sorted or rotated, or you can ask a yes-or-no question whose answer flips only once across the range of possible answers.
Common pitfalls
Loops that never end because the bounds stop moving, an off-by-one final index, and integer overflow when computing the midpoint in some languages.

Related preparation

These are PrepKit study suggestions, not employer endorsements or predictions of interview questions.

Pages that include this

Common questions

Where can I practice Search a 2D Matrix?

Open it on leetcode.com. PrepKit links there and does not copy the problem.

What pattern does Search a 2D Matrix use?

PrepKit files it under binary search, at Medium difficulty.

Source and license

Source and license

License:
MIT License
Author:
Enzo Davico
Source version:
5c033cb
Last checked against the source:
Changes:
PrepKit kept only each problem's title, pattern, difficulty, list membership, and LeetCode link. Solutions, quizzes, Anki content, NeetCode links, videos, and ordering are not copied.
Visit original source
Full license and copyright notice

MIT License Copyright (c) 2023 Enzo Davico Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.