0
0
DSA Typescriptprogramming~30 mins

Search in 2D Matrix in DSA Typescript - Build from Scratch

Choose your learning style9 modes available
Search in 2D Matrix
📖 Scenario: You are working with a grid-like map that stores numbers in rows and columns. You want to find if a specific number exists in this map.
🎯 Goal: Build a program that searches for a given number in a 2D matrix and tells if it is found or not.
📋 What You'll Learn
Create a 2D array called matrix with exact numbers
Create a variable called target with the number to search
Use nested for loops with variables row and col to check each element
Print "Found" if the target is in the matrix, otherwise print "Not Found"
💡 Why This Matters
🌍 Real World
Searching in 2D grids is common in games, maps, and image processing where data is arranged in rows and columns.
💼 Career
Understanding how to search in 2D arrays is important for software developers working with matrices, tables, or grid-based data.
Progress0 / 4 steps
1
Create the 2D matrix
Create a 2D array called matrix with these exact rows: [1, 3, 5], [7, 9, 11], [13, 15, 17]
DSA Typescript
Hint

Use square brackets to create arrays inside an array.

2
Set the target number
Create a variable called target and set it to 9
DSA Typescript
Hint

Use const target: number = 9; to create the variable.

3
Search for the target in the matrix
Use nested for loops with variables row and col to check each element in matrix. Create a boolean variable found set to false before loops. If matrix[row][col] equals target, set found to true and break both loops.
DSA Typescript
Hint

Use two for loops, one inside the other, to check each element.

4
Print the search result
Print "Found" if found is true, otherwise print "Not Found"
DSA Typescript
Hint

Use console.log to print the result based on the found variable.