This repository has been archived by the owner on May 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudentsWeight.py
81 lines (44 loc) · 2.27 KB
/
studentsWeight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
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 their heights appear in A). For the i-th 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 is no such row, the student will create a new row. Your task is to find the minimum number of rows created.
Write a function that, given a non-empty array A containing N integers, denoting the heights of the students, returns the minimum number 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 have height = 4, and so on.
For the first student, there is no row, so the 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 fifth student, all the students in Row1 and Row2 have height greater than 1. So, the student can stand in either of the two rows.
Row1 = [5, 4, 3, 1]
Row2 = [6]
Since two rows are created, the function should return 2.
Assume that:
N is an integer within the range [1..1,000]
each element of array A is an integer within the range [1..10,000]
In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment
"""
import sys
def solution(A):
"""Your solution goes here."""
res=1
index=A[1]
contador=0
for i in A:
if(index<i):
res = res +1
if(contador <len(A)-1):
contador = contador+1
index = A[contador]
return res
pass
def main():
"""Read from stdin, solve the problem, write answer to stdout."""
input = sys.stdin.readline().split()
A = [int(x) for x in input[0].split(",")]
sys.stdout.write(str(solution(A)))
if __name__ == "__main__":
main()