Given two integers N and M, the task is to print an N x M matrix such that each row and column contain all the vowels in it. If it is impossible to do so, then print -1.
Input: N = 5, M = 5
a e i o u
e i o u a
i o u a e
o u a e i
u a e i o
Input: N = 6, M = 2
Approach: Since the number of vowels are 5, hence we need a minimum of 5 rows and 5 columns in order to generate a valid matrix. A pattern can be followed by filling “aeiouaeiou..” in the first row, “eiouaeio..” in the second row and so on and the generated matrix will contain all the vowels in every row and column.
Below is the implementation of the above approach:
a e i o u e i o u a i o u a e o u a e i u a e i o
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Print matrix in zig-zag fashion from the last column
- Print matrix in snake pattern from the last column
- Print all elements in sorted order from row and column wise sorted matrix
- heapq in Python to print all elements in sorted order from row and column wise sorted matrix
- Check if a given matrix can be converted to another given matrix by row and column exchanges
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Print reverse string after removing vowels
- Print number of words, vowels and frequency of each character
- Sum of middle row and column in Matrix
- Maximum sum of a Matrix where each value is from a unique row and column
- Program to find the Sum of each Row and each Column of a Matrix
- Minimum element of each row and each column in a matrix
- Check if sums of i-th row and i-th column are same in matrix
- Find column with maximum sum in a Matrix
- Given a Boolean Matrix, find k such that all elements in k'th row are 0 and k'th column are 1.
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.