#C3921. Find the Bounding Frame
Find the Bounding Frame
Find the Bounding Frame
You are given a grid with ( n ) rows and ( m ) columns. Each cell in this grid is represented by a character which is either a dot (( . )) or a hash (( # )). The task is to identify the smallest rectangular frame that encloses all the decorated cells (cells with a ( # )). The coordinates of the frame should be represented by the top-left and bottom-right corners in 1-indexed format. If no decorated cell is found, output exactly "No frame needed".
Input: The first line contains two integers ( n ) and ( m ) denoting the number of rows and columns respectively. The following ( n ) lines contain a string of ( m ) characters representing the grid.
Output: If there is at least one decorated cell, print four space-separated integers ( r_1 ), ( c_1 ), ( r_2 ), and ( c_2 ) corresponding to the coordinates (row and column) of the top-left and bottom-right corners of the smallest frame that encloses all the ( # ) cells. If no decorated cell exists, print "No frame needed".
inputFormat
Input Format:
The first line contains two integers \( n \) and \( m \) (the number of rows and columns).
Each of the next \( n \) lines contains a string of length \( m \) consisting of '.' and '#' characters.
outputFormat
Output Format:
If there is at least one '#' in the grid, output four space-separated integers: \( r_1 \), \( c_1 \), \( r_2 \), \( c_2 \), where \( (r_1, c_1) \) is the top-left and \( (r_2, c_2) \) is the bottom-right coordinate of the frame, using 1-indexed positions. Otherwise, output "No frame needed".
4 4
....
....
....
....
No frame needed