FastPrepSearch a 2D Matrix II
Problems/Search a 2D Matrix II

Search a 2D Matrix II

Bloomberg LP logoBloomberg LP● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: An experienced full-stack candidate's report from a Bloomberg live coding round names this task as the second of two questions and calls it a routine one: look for a target value in a grid that is ordered along both its rows and its columns. It gives no signature, limits or example, and does not say what to return.

Everything else here is our practice choice. The function returns true or false. Rows and columns never decrease, so values may repeat. The grid has 1 to 100 rows and 1 to 100 columns, all rows have the same length, and every value and the target are from -100000 to 100000.

The judged task matches the report at about 85%.

You are given a grid of integers matrix and an integer target. In every row the values never decrease from left to right, and in every column they never decrease from top to bottom. Values may repeat.

Return true if target appears anywhere in matrix, and false otherwise.

Function

searchMatrix(matrix: int[][], target: int) → boolean

Examples

Example 1

matrix = [[2,5,9],[4,8,12],[7,10,15]]target = 10return = true
matrix
012025914812271015

Start at the top-right corner, 9. It is smaller than 10, and everything left of it in that row is smaller still, so drop the top row and move down to 12.

12 is bigger than 10, and everything below it in that column is bigger still, so drop the last column and move left to 8. 8 is smaller than 10, so move down to 10. That is the target, so the answer is true.

Example 2

matrix = [[2,5,9],[4,8,12],[7,10,15]]target = 6return = false
matrix
012025914812271015

From the top-right corner the walk goes 9 (too big, move left), 5 (too small, move down), 8 (too big, move left), 4 (too small, move down), 7 (too big, move left). Moving left from 7 leaves the grid, so 6 is not in the matrix and the answer is false.

Example 3

matrix = [[-3]]target = -3return = true
matrix
00-3

The matrix has one cell, and it holds the target -3.

Example 4

matrix = [[1,3,3,8],[2,3,6,9]]target = 7return = false
matrix
01230133812369

Values may repeat, like the three 3s here. The value 7 does not appear: the first row jumps from 3 to 8 and the second row from 6 to 9. The answer is false.

Constraints

  • 1 <= matrix.length <= 100
  • 1 <= matrix[i].length <= 100. All rows have the same length.
  • -100000 <= matrix[i][j] <= 100000
  • -100000 <= target <= 100000
  • Each row is sorted in non-decreasing order from left to right, and each column is sorted in non-decreasing order from top to bottom.

More Bloomberg LP Phone Screen questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Find the Safest Path in a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • Search a Row-Major Sorted MatrixMotive · ONSITE INTERVIEWMotive interview questions
  • Grid Path With the Most ClearanceDocuSign · OADocuSign interview questions
  • Largest Square Sub-Grid Within a Sum LimitC3.ai · OAC3.ai interview questions
  • Server SelectionAirbnb · OAAirbnb interview questions
  • Koko Eating BananasThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Find First and Last Position in a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions

Interview reports that mention this question

  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        // Write your code here.
    }
}
Checking account…