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
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.
- Check if it is possible to create a matrix such that every row has A 1s and every column has B 1s
- 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
- Given a Boolean Matrix, find k such that all elements in k'th row are 0 and k'th column are 1.
- 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
- Sum of matrix in which each element is absolute difference of its row and column numbers
- Sum of matrix element where each elements is integer division of row and column
- Minimum operations required to make each row and column of matrix equals
- Maximum sum of a Matrix where each value is from a unique row and column
- Count of ways to generate a Matrix with product of each row and column as 1 or -1
- Construct a Binary Matrix whose sum of each row and column is a Prime Number
- Find trace of matrix formed by adding Row-major and Column-major order of same matrix
- Check if a given matrix can be converted to another given matrix by row and column exchanges
- Find a Square Matrix such that sum of elements in every row and column is K
- Construct a matrix such that union of ith row and ith column contains every element from 1 to 2N-1
- Place N^2 numbers in matrix such that every row has an equal sum
- Find sum of all elements in a matrix except the elements in row and/or column of given cell?
- Find all matrix elements which are minimum in their row and maximum in their column
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
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.