Question: PYTHON3: You are given an array A representing heights of students. All the students are asked to stand in rows. The students arrive by one,
PYTHON3:
You are given an array A representing heights of students. All the students are asked to stand in rows. The students arrive by one, sequentially(as the heights appear in A). For the ith student, if there is a row in which all the students are taller than A[i], the student will stand in one of such rows. If there's no such row, the student will create a new row. Your task is to find the minimum number of rows created.
Write a function def solution(arr) that given a non-empty array A containing N integers, denoting the heights of the students, return the minimum order of rows created.
For example, given A = [5,4,3,6,1], the function should return 2. Students will arrive in sequential order from A[0] to A[N-1], So, the first student will have height = 5, the second student will create a new row.
Row1 = [5]
For the second student, all the students in row1 have height greater than 4. So the student will stand in row1. Row1 = [5,4]
Similarly, for the third student, all the students in Row1 have height greater than 3. So the student will stand in Row1
Row1 = [5,4,3]
For the fourth student, there is no row in which all the students have height greater than 6. So, the student will create a new row Row1 = [5,4,3] Row2 = [6]
For the 5th student, all the students in row1 and row2 have height greater than 1. So the student can stand in either of two rows.
Row1 = [5,4,3,1] Row2 = [6]
Since two rows are created, the function should return 2.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
