Given a Character matrix as input, the task is to check whether all the enemies are killed or not based on below conditions:
1. The matrix can contain 3 characters
X –> Denotes the War area.
B –> Denotes the bomb.
E –> Denotes the Enemies.
2. Bomb ‘B’ can blast in only horizontal and vertical directions from one end to another.
3. If all enemies are killed by the present bombs, print Yes, else print No
Input: matrix = XXEX XBXX XEXX XXBX Output: Yes Input: matrix = XXEX XBXX XEXX XXXX Output: No
Approach: The given problem can be solved by the following approach:
- Get the character Matrix
- Traverse to find all bomb indices in the matrix
- For each bomb found, see if any enemy is present in its vertical or horizontal direction. If present kill that enemy, i.e. change E to X
- After all traversals, check if any enemy is present in the matrix or not.
- Print Yes if all enemies are killed, else print No.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Maximum bishops that can be placed on N*N chessboard
- Maximum non-attacking Rooks that can be placed on an N*N Chessboard
- Find position of non-attacking Rooks in lexicographic order that can be placed on N*N chessboard
- Program to check diagonal matrix and scalar matrix
- Check if it is possible to make the given matrix increasing matrix or not
- Program to check if a matrix is Binary matrix or not
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Check if a given matrix can be converted to another given matrix by row and column exchanges
- Check if all rows of a matrix are circular rotations of each other
- Check whether row or column swaps produce maximum size binary sub-matrix with all 1s
- Ways of filling matrix such that product of all rows and all columns are equal to unity
- Maximize sum of diagonal of a matrix by rotating all rows or all columns
- Maximize sum of N X N upper left sub-matrix from given 2N X 2N matrix
- Circular Matrix (Construct a matrix with numbers 1 to m*n in spiral way)
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Count frequency of k in a matrix of size n where matrix(i, j) = i+j
- Program to convert given Matrix to a Diagonal Matrix
- Maximum trace possible for any sub-matrix of the given matrix
- Minimum number of steps to convert a given matrix into Upper Hessenberg matrix
- Minimum steps required to convert the matrix into lower hessenberg matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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 : Rajput-Ji