You are give a matrix (a list of lists) of DISTINCT integers and a target number. Each row in the matrix is SORTED and each column in the matrix is SORTED. Our matrix does not necessarily have the same height and width. Write a function that returns a list of the row and column indices of the target integer

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 16SA
icon
Related questions
Question

13

 

Python question please provide screen shot of the code:
SEARCH IN MATRIX
You are give a matrix (a list of lists) of DISTINCT integers and a target number.
Each row in the matrix is SORTED and each column in the matrix is SORTED.
Our matrix does not necessarily have the same height and width.
Write a function that returns a list of the row and column indices of the target integer
IF it is contained in the matrix, otherwise return [-1, -1].
EXAMPLE INPUT
matrix
[
[1,4,7,12,15,1000],
[2,5,19,31,32,1001],
[3,8,24,33,35,1002],
[40,41,42,44,45,1003],
=
[99, 100, 103,106,128,1004]
]
target=44
EXAMPLE OUTPUT
result = [3,3]
Finish the code bellow with given requirements:
def search_in_matrix(matrix, target):
pass
Transcribed Image Text:Python question please provide screen shot of the code: SEARCH IN MATRIX You are give a matrix (a list of lists) of DISTINCT integers and a target number. Each row in the matrix is SORTED and each column in the matrix is SORTED. Our matrix does not necessarily have the same height and width. Write a function that returns a list of the row and column indices of the target integer IF it is contained in the matrix, otherwise return [-1, -1]. EXAMPLE INPUT matrix [ [1,4,7,12,15,1000], [2,5,19,31,32,1001], [3,8,24,33,35,1002], [40,41,42,44,45,1003], = [99, 100, 103,106,128,1004] ] target=44 EXAMPLE OUTPUT result = [3,3] Finish the code bellow with given requirements: def search_in_matrix(matrix, target): pass
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning