Flood Fill Algorithm
Practice
3.5 (2 votes)
Easy Medium
Problem
30% Success 1060 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There is a robot named Micro in a matrix A, of integers of size \(N \times M\), initially placed at the cell \((X_1, Y_1)\). He has to rescue his princess Mini placed at cell \((X_2, Y_2)\). Rows are numbered from 1 to N and columns are numbered from 1 to M. He can move one step in either of the four directions: up, down, left and right. Also he can make a move if value at cell he is currently at is strictly less than the value at cell he is moving to. Help Micro find out if he can rescue his princess or not.

Input:
First line consists of T the number of test case.
In each test case first line consists of six space separated integers denoting \(N, M, X_1, Y_1, X_2, Y_2 \). Then N lines follow each consisting of M space separated integers denoting the matrix.

Output:
For each test case, print in a new line, "YES" (without quotes) if Micro can rescue Mini otherwise print "NO" (without quotes).

Constraints:
\( 1\le T \le 5\)
\(1 \le N, M \le 10 \)
\(1 \le X_1, X_2 \le N \)
\(1 \le Y_1, Y_2 \le M \)
\(1 \le A[i][j] \le 100 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
22 votes
Tags:
ApprovedData StructuresEasyGreedy AlgorithmsOpen
Points:30
7 votes
Tags:
Easy
Points:10
1 votes
Tags:
Basic MathAlgorithmsMath
Editorial

No editorial available for this problem.