File tree Expand file tree Collapse file tree 6 files changed +173
-0
lines changed Expand file tree Collapse file tree 6 files changed +173
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/bin/python3
2+
3+ import os
4+ import sys
5+
6+ #
7+ # Complete the birthdayCakeCandles function below.
8+ #
9+ def birthdayCakeCandles (n , ar ):
10+ max_height = max (ar )
11+ nb_max_height = 0
12+ for val in ar :
13+ if max_height == val :
14+ nb_max_height += 1
15+ return nb_max_height
16+
17+
18+ if __name__ == '__main__' :
19+ f = open (os .environ ['OUTPUT_PATH' ], 'w' )
20+
21+ n = int (input ())
22+
23+ ar = list (map (int , input ().rstrip ().split ()))
24+
25+ result = birthdayCakeCandles (n , ar )
26+
27+ f .write (str (result ) + '\n ' )
28+
29+ f .close ()
Original file line number Diff line number Diff line change 1+ #https://www.hackerrank.com/challenges/diagonal-difference/problem
2+
3+ #!/bin/python3
4+
5+ import os
6+ import sys
7+
8+ #
9+ # Complete the diagonalDifference function below.
10+ #
11+ def diagonalDifference (a ):
12+ length = len (a [0 ])
13+ sum1 = 0
14+ for i in range (length ):
15+ sum1 += a [i ][i ]
16+ sum2 = 0
17+ for i in range (length ):
18+ sum2 += a [i ][length - i - 1 ]
19+
20+ return abs (sum1 - sum2 )
21+
22+ if __name__ == '__main__' :
23+ f = open (os .environ ['OUTPUT_PATH' ], 'w' )
24+
25+ n = int (input ())
26+
27+ a = []
28+
29+ for _ in range (n ):
30+ a .append (list (map (int , input ().rstrip ().split ())))
31+
32+ result = diagonalDifference (a )
33+
34+ f .write (str (result ) + '\n ' )
35+
36+ f .close ()
Original file line number Diff line number Diff line change 1+ #https://www.hackerrank.com/challenges/mini-max-sum/problem
2+
3+ #!/bin/python3
4+
5+ import os
6+ import sys
7+
8+ #
9+ # Complete the miniMaxSum function below.
10+ #
11+ def miniMaxSum (arr ):
12+ ar_total = []
13+ for i in range (len (arr )):
14+ ar = [arr [j ] for j in range (len (arr )) if i != j ]
15+ ar_total .append (sum (ar ))
16+ print ('{} {}' .format (min (ar_total ), max (ar_total )))
17+
18+
19+ if __name__ == '__main__' :
20+ arr = list (map (int , input ().rstrip ().split ()))
21+
22+ miniMaxSum (arr )
Original file line number Diff line number Diff line change 1+ #https://www.hackerrank.com/challenges/plus-minus/problem
2+
3+ #!/bin/python3
4+
5+ import os
6+ import sys
7+
8+ #
9+ # Complete the plusMinus function below.
10+ #
11+ def plusMinus (arr ):
12+ nb_pos = 0
13+ nb_neg = 0
14+ nb_zero = 0
15+ for val in arr :
16+ if val > 0 :
17+ nb_pos += 1
18+ elif val < 0 :
19+ nb_neg += 1
20+ else :
21+ nb_zero += 1
22+
23+ print ('{}' .format (round (nb_pos / len (arr ), 6 )))
24+ print ('{}' .format (round (nb_neg / len (arr ), 6 )))
25+ print ('{}' .format (round (nb_zero / len (arr ), 6 )))
26+
27+ if __name__ == '__main__' :
28+ n = int (input ())
29+
30+ arr = list (map (int , input ().rstrip ().split ()))
31+
32+ plusMinus (arr )
Original file line number Diff line number Diff line change 1+ #https://www.hackerrank.com/challenges/staircase/problem
2+
3+ #!/bin/python3
4+
5+ import os
6+ import sys
7+
8+ #
9+ # Complete the staircase function below.
10+ #
11+ def staircase (n ):
12+ for i in range (n ):
13+ str = ' ' * (n - i - 1 ) + '#' * (i + 1 )
14+ print (str )
15+
16+ if __name__ == '__main__' :
17+ n = int (input ())
18+
19+ staircase (n )
Original file line number Diff line number Diff line change 1+ #https://www.hackerrank.com/challenges/time-conversion/problem
2+
3+ #!/bin/python3
4+
5+ import os
6+ import sys
7+
8+ #
9+ # Complete the timeConversion function below.
10+ #
11+ def timeConversion (s ):
12+ arr = s .split (':' )
13+ hour = arr [0 ]
14+ minute = arr [1 ]
15+ seconds = arr [2 ][:- 2 ]
16+ if 'PM' in arr [2 ] or 'pm' in arr [2 ]:
17+ if int (hour ) != 12 :
18+ hour = int (hour ) + 12
19+ elif 'AM' in arr [2 ] or 'am' in arr [2 ]:
20+ if int (hour ) == 12 :
21+ hour = '00'
22+
23+ return str (hour ) + ':' + str (minute ) + ':' + str (seconds )
24+
25+
26+ if __name__ == '__main__' :
27+ f = open (os .environ ['OUTPUT_PATH' ], 'w' )
28+
29+ s = input ()
30+
31+ result = timeConversion (s )
32+
33+ f .write (result + '\n ' )
34+
35+ f .close ()
You can’t perform that action at this time.
0 commit comments