PageSourceSearch

https://codemia.io/_next/static/chunks/11149.a18b41eed2314bf1.js

js codemia.io collected 2026-10-02 04:28:02 UTC 8,077 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[11149],{11149:function(t,e,r){r.r(e),r.d(e,{SearchMatrixII:function(){return a}});var n=r(62638);let i=[[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]],a={id:"search-a-2d-matrix-ii",label:"Search a 2D Matrix II",description:"Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom.",constraints:["$m == \\text{matrix.length}$","$n == \\text{matrix}[i].\\text{length}$","$1 \\leq n, m \\leq 300$","$-10^9 \\leq \\text{matrix}[i][j], \\text{target} \\leq 10^9$","All integers in each row are sorted in ascending order.","All integers in each column are sorted in ascending order."],topics:["array","binary-search","divide-and-conquer","matrix"],companies:["Amazon","Microsoft","Bloomberg","Apple"],category:"Binary Search",difficulty:"Medium",code:{python:"class Solution:\n    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:\n        if not matrix: return False\n        r, c = 0, len(matrix[0]) - 1\n        \n        while r < len(matrix) and c >= 0:\n            if matrix[r][c] == target:\n                return True\n            elif matrix[r][c] > target:\n                c -= 1\n            else:\n                r += 1\n        return False",javascript:"function searchMatrix(matrix, target) {\n    if (!matrix.length) return false;\n    let r = 0, c = matrix[0].length - 1;\n    \n    while (r < matrix.length && c >= 0) {\n        if (matrix[r][c] === target) return true;\n        else if (matrix[r][c] > target) c--;\n        else r++;\n    }\n    return false;\n}",typescript:"function searchMatrix(matrix: number[][], target: number): boolean {\n    if (!matrix.length) return false;\n    let r = 0, c = matrix[0].length - 1;\n    \n    while (r < matrix.length && c >= 0) {\n        if (matrix[r][c] === target) return true;\n        else if (matrix[r][c] > target) c--;\n        else r++;\n    }\n    return false;\n}",java:"class Solution {\n    public boolean searchMatrix(int[][] matrix, int target) {\n        if (matrix == null || matrix.length == 0) return false;\n        int r = 0, c = matrix[0].length - 1;\n        \n        while (r < matrix.length && c >= 0) {\n            if (matrix[r][c] == target) return true;\n            else if (matrix[r][c] > target) c--;\n            else r++;\n        }\n        return false;\n    }\n}",cpp:"class Solution {\npublic:\n    bool searchMatrix(vector<vector<int>>& matrix, int target) {\n        if (matrix.empty()) return false;\n        int r = 0, c = matrix[0].size() - 1;\n        \n        while (r < matrix.size() && c >= 0) {\n            if (matrix[r][c] == target) return true;\n            else if (matrix[r][c] > target) c--;\n            else r++;\n        }\n        return false;\n    }\n};",csharp:"public class Solution {\n    public bool SearchMatrix(int[][] matrix, int target) {\n        if (matrix == null || matrix.Length == 0) return false;\n        int r = 0, c = matrix[0].Length - 1;\n        \n        while (r < matrix.Length && c >= 0) {\n            if (matrix[r][c] == target) return true;\n            else if (matrix[r][c] > target) c--;\n            else r++;\n        }\n        return false;\n    }\n}",go:"func searchMatrix(matrix [][]int, target int) bool {\n    if len(matrix) == 0 { return false }\n    r, c := 0, len(matrix[0])-1\n    \n    for r < len(matrix) && c >= 0 {\n        if matrix[r][c] == target { return true }\n        if matrix[r][c] > target {\n            c--\n        } else {\n            r++\n        }\n    }\n    return false\n}"},lineMapping:{python:{init:4,loop:6,check_eq:7,found:8,check_gt:9,dec_c:10,inc_r:12,not_found:13},javascript:{init:3,loop:5,check_eq:6,found:6,check_gt:7,dec_c:7,inc_r:8,not_found:10},typescript:{init:3,loop:5,check_eq:6,found:6,check_gt:7,dec_c:7,inc_r:8,not_found:10},java:{init:4,loop:6,check_eq:7,found:7,check_gt:8,dec_c:8,inc_r:9,not_found:11},cpp:{init:4,loop:6,check_eq:7,found:7,check_gt:8,dec_c:8,inc_r:9,not_found:11},csharp:{init:4,loop:6,check_eq:7,found:7,check_gt:8,dec_c:8,inc_r:9,not_found:11},go:{init:3,loop:5,check_eq:6,found:6,check_gt:7,dec_c:8,inc_r:10,not_found:13}},presets:[{label:"Example 1",data:{matrix:i,target:5},expected:"true"},{label:"Example 2",data:{matrix:i,target:20},expected:"false"}],defaultInput:{matrix:i,target:5},defaultExpected:"true",Renderer:n.o,functionSignature:{name:"searchMatrix",params:[{name:"matrix",type:"int[][]"},{name:"target",type:"int"}],returnType:"boolean"},starterCode:{python:"class Solution:\n    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:\n        # Write your solution here\n        return False",javascript:"/**\n * @param {number[][]} matrix\n * @param {number} target\n * @return {boolean}\n */\nvar searchMatrix = function(matrix, target) {\n    // Write your solution here\n    return false;\n};",typescript:"function searchMatrix(matrix: number[][], target: number): boolean {\n    // Write your solution here\n    return false;\n}",java:"class Solution {\n    public boolean searchMatrix(int[][] matrix, int target) {\n        // Write your solution here\n        return false;\n    }\n}",cpp:"class Solution {\npublic:\n    bool searchMatrix(vector<vector<int>>& matrix, int target) {\n        // Write your solution here\n        return false;\n    }\n};",csharp:"public class Solution {\n    public bool SearchMatrix(int[][] matrix, int target) {\n        // Write your solution here\n        return false;\n    }\n}",go:"func searchMatrix(matrix [][]int, target int) bool {\n    // Write your solution here\n    return false\n}"},generateFrames:t=>{let{matrix:e,target:r}=t,n=[],i=[],a=(t,r,n)=>({matrix:JSON.parse(JSON.stringify(e)),activeCells:[...i,{r,c:n,color:"#f59e0b"}],message:t});if(!e||!e.length)return n;let c=0,o=e[0].length-1;for(n.push({stepId:"init",line:1,state:a("Start at top-right",c,o)});c<e.length&&o>=0;){if(n.push({stepId:"loop",line:2,state:a("Check (".concat(c,",").concat(o,"): ").concat(e[c][o]),c,o)}),e[c][o]===r)return n.push({stepId:"found",line:3,state:{...a("Found target!",c,o),activeCells:[...i,{r:c,c:o,color:"#22c55e"}]}}),n;e[c][o]>r?(i.push({r:c,c:o,color:"#3f3f46"}),n.push({stepId:"check_gt",line:4,state:a("".concat(e[c][o]," > ").concat(r,". Go left."),c,o)}),o--):(i.push({r:c,c:o,color:"#3f3f46"}),n.push({stepId:"inc_r",line:5,state:a("".concat(e[c][o]," < ").concat(r,". Go down."),c,o)}),c++)}return n.push({stepId:"not_found",line:6,state:a("Out of bounds. Not found.",-1,-1)}),n}}},62638:function(t,e,r){r.d(e,{o:function(){return o}});var n=r(57437);r(2265);var i=r(63832),a=r(46387),c=r(19902);let o=t=>{let{frame:e}=t,{matrix:r,activeCells:o,message:l,result:s}=e.state;return(0,n.jsxs)(i.Z,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:6,p:4,width:"100%",height:"100%"},children:[(0,n.jsx)(i.Z,{sx:{height:40},children:l&&(0,n.jsx)(a.Z,{color:"#a1a1aa",children:l})}),(0,n.jsx)(i.Z,{sx:{display:"flex",flexDirection:"column",gap:1},children:(r||[]).map((t,e)=>(0,n.jsx)(i.Z,{sx:{display:"flex",gap:1},children:t.map((t,r)=>{let i=null==o?void 0:o.find(t=>t.r===e&&t.c===r),l="#27272a",s="#3f3f46";return i&&(l=i.color||"#3b82f6",s=i.color?i.color:"#60a5fa"),(0,n.jsx)(c.Z,{elevation:i?6:1,sx:{width:48,height:48,display:"flex",alignItems:"center",justifyContent:"center",bgcolor:l,border:"2px s
1olid ".concat(s),transition:"all 0.3s ease"},children:(0,n.jsx)(a.Z,{fontWeight:"bold",color:"#fff",children:t})},r)})},e))}),s&&(0,n.jsxs)(i.Z,{sx:{display:"flex",flexDirection:"column",alignItems:"center",gap:1,width:"100%",maxWidth:600},children:[(0,n.jsx)(a.Z,{variant:"caption",color:"#a1a1aa",children:"Result"}),(0,n.jsx)(c.Z,{sx:{p:2,bgcolor:"#18181b",border:"1px solid #3f3f46",width:"100%"},children:(0,n.jsxs)(a.Z,{sx:{wordBreak:"break-all"},children:["[",s.join(", "),"]"]})})]})]})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.