Short Problem Definition:
Maria plays college basketball and wants to go pro. Each season she maintains a record of her play. She tabulates the number of times she breaks her season record for most points and least points in a game. Points scored in the first game establish her record for the season, and she begins counting from there.
Link
Complexity:
time complexity is O(N)
space complexity is O(1)
Execution:
Just track the min and max.
Solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/bin/python import sys def getRecord(s): min_ele = s[ 0 ] max_ele = s[ 0 ] min_cnt = 0 max_cnt = 0 for ele in s: if ele > max_ele: max_ele = ele max_cnt + = 1 if ele < min_ele: min_ele = ele min_cnt + = 1 return [max_cnt, min_cnt] n = int ( raw_input ().strip()) s = map ( int , raw_input ().strip().split( ' ' )) result = getRecord(s) print " " .join( map ( str , result)) |