Jobs
Interviews

Solve Search in Sorted Matrix using Lua Language

Solve Search in Sorted Matrix using Lua to enhance your skills with lua coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.

Search in Sorted Matrix

Difficulty : Medium

Categories :

  • Searching algorithms

Given a 2D matrix of integers where each row is sorted in ascending order and the first element of each row is greater than the last element of the previous row, implement a function to search for a target value. Return [row, col] if found, or [-1, -1] if not found.

Constraints:

  • 1 ≤ matrix.length, matrix[i].length ≤ 100
  • -1000 ≤ matrix[i][j] ≤ 1000
  • Each row is sorted in ascending order
  • First element of row is greater than last element of previous row
  • Must achieve better than O(n*m) time complexity

Examples:

Input:
matrix = [
 [1,3,5,7],
 [10,11,16,20],
 [23,30,34,60]
]
target = 3
Output: [0,1]
Explanation: Target 3 found at row 0, column 1
Input:
matrix = [
 [1,3,5],
 [7,9,11]
]
target = 4
Output: [-1,-1]
Explanation: Target 4 not found

Problem Solving

Input

What You'll Find Here

Real-World Applications Solve problems inspired by Lua's common use cases, such as game development and embedded systems.

Step-by-Step Guidance Break down Lua's concepts into digestible lessons.

Practical Skills Build hands-on experience with Lua for real-world projects.

Choose from the following categories