Codey and Number Grid
https://www.hackerrank.com/contests/codenection-2023-preliminary-round-open-category/challenges/cn-c17
Question
Codey finds itself in a desolate planet. The planet, shrouded in mystery, is known for its harsh, alien terrain — a place where every decision is a matter of survival. Here, in this strange land, Codey discovers a ( n
rows and m
columns) grid imprinted with unique numbers that seem to hold the keys to life itself.
Trapped on this planet, Codey faces a huge challenge. Its very survival depends on its ability to decipher this grid. It must uncover k
, the maximum connected area within the grid that contains every number from 1
to k
. Two cells can only be connected if they share an edge.
As time runs out and the situation becomes more dangerous, Codey needs your help to find k
, the largest possible connected area k
that meets the condition. Can you assist Codey in determining the value of k
to survive this challenge?
Input Format
The first line contains two integers, n
and m
, where n
represents the number of rows and m
represents the columns in the 2D grid.
The following lines contain the numbers , which provides a representation of the 2D grid.
Constraints
Every is guaranteed unique.
Output Format
Output k, the maximum connected area within the grid that contains every number from 1 to k.
Sample Inputs:
Last updated