Given a room with square grids having ‘*’ and ‘.’ representing untidy and normal cells respectively.
You need to find whether room can be cleaned or not.
There is a machine which helps you in this task, but it is capable of cleaning only normal cell. Untidy cells cannot be cleaned with machine, until you have cleaned the normal cell in its row or column. Now, see to it whether room can be cleaned or not.
The input is as follows :
First line contains the size of the room. The next n lines contains description for each row where the row[i][j] is ‘‘ if it is more untidy than others else it is ‘‘ if it is normal cell.
Input : 3 .** .** .** Output :Yes, the room can be cleaned. 1 1 2 1 3 1 Input :4 **** ..*. ..*. ..*. Output : house cannot be cleaned.
The minimum number of cells can be n. It is the only answer possible as it need to have an element of type ‘‘ in every different row and column. If particular column and a given row contain ‘‘ in all the cells then, it is known that the house cannot be cleaned. Traverse every row and find the ‘‘ that can be used for the machine. Use this step two times, check every column for every row and then check for every row for every column. Then check if any of the two gives answer as n. If yes then house can be cleaned otherwise not. This approach will give us the minimum answer required.
In the first example the machine will clean cell (1, 1), (2, 1), (3, 1) in order to clean the entire room.
In the second example every cell in the row has ‘‘ and every cell in column contains ‘‘, therefore the house cannot be cleaned. row cannot be cleaned in any way.
Yes, the house can be cleaned. 1 1 2 1 3 1
- Reverse a subarray of the given array to minimize the sum of elements at even position
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Count of square free divisors of a given number
- Minimum cost of reducing Array by merging any adjacent elements repetitively
- Largest number M less than N such that XOR of M and N is even
- Minimize operations required to make each element of Array equal to it's index value
- K-th term from given N merged Arithmetic Progressions
- Count all indices of cyclic regular parenthesis
- Count of all values of N in [L, R] such that count of primes upto N is also prime
- Shortest path in a complement graph
- Maximum number of bridges in a path of a given graph
- Count of prime factors of N to be added at each step to convert N to M
- Maximize jobs that can be completed under given constraint
- Minimize number of boxes by putting small box inside bigger one
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : SHUBHAMSINGH10