Skip to content

Commit 6ebba8c

Browse files
committed
+ HackerRank 1week preparation kit solving
+ HackerRank Python builtin libraries usage
1 parent 9b40c18 commit 6ebba8c

File tree

7 files changed

+10321
-5
lines changed

7 files changed

+10321
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
Problem solved: https://www.hackerrank.com/challenges/one-week-preparation-kit-mini-max-sum/problem?h_l=interview&isFullScreen=true&playlist_slugs%5B%5D%5B%5D=preparation-kits&playlist_slugs%5B%5D%5B%5D=one-week-preparation-kit&playlist_slugs%5B%5D%5B%5D=one-week-day-one
3+
"""
4+
5+
6+
def miniMaxSum(arr):
7+
sorted_arr = sorted(arr)
8+
print(sum(sorted_arr[:4]), sum(sorted_arr[-4:]))
9+
10+
11+
if __name__ == '__main__':
12+
arr = list(map(int, input().rstrip().split()))
13+
14+
miniMaxSum(arr)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
Problem solved: https://www.hackerrank.com/challenges/one-week-preparation-kit-plus-minus/problem?isFullScreen=true&h_l=interview&playlist_slugs%5B%5D=preparation-kits&playlist_slugs%5B%5D=one-week-preparation-kit&playlist_slugs%5B%5D=one-week-day-one
3+
"""
4+
# !/bin/python3
5+
6+
import math
7+
import os
8+
import random
9+
import re
10+
import sys
11+
from collections import defaultdict
12+
13+
14+
#
15+
# Complete the 'plusMinus' function below.
16+
#
17+
# The function accepts INTEGER_ARRAY arr as parameter.
18+
#
19+
20+
def plusMinus(arr):
21+
d = defaultdict(int)
22+
for i in arr:
23+
if i > 0:
24+
d['pos'] += 1
25+
elif i < 0:
26+
d['neg'] += 1
27+
else:
28+
d['zero'] += 1
29+
30+
# find ratios of positive, negative and zero
31+
pos_ratio = d['pos'] / len(arr)
32+
neg_ratio = d['neg'] / len(arr)
33+
zero_ratio = d['zero'] / len(arr)
34+
35+
# print the ratios
36+
print(f"{pos_ratio:.06f}")
37+
print(f"{neg_ratio:.06f}")
38+
print(f"{zero_ratio:.06f}")
39+
40+
41+
if __name__ == '__main__':
42+
n = int(input().strip())
43+
44+
arr = list(map(int, input().rstrip().split()))
45+
46+
plusMinus(arr)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/python3
2+
3+
"""
4+
Problem solved: https://www.hackerrank.com/challenges/one-week-preparation-kit-time-conversion/problem?h_l=interview&isFullScreen=true&playlist_slugs%5B%5D%5B%5D=preparation-kits&playlist_slugs%5B%5D%5B%5D=one-week-preparation-kit&playlist_slugs%5B%5D%5B%5D=one-week-day-one
5+
"""
6+
7+
import math
8+
import os
9+
import random
10+
import re
11+
import sys
12+
from datetime import datetime
13+
14+
15+
#
16+
# Complete the 'timeConversion' function below.
17+
#
18+
# The function is expected to return a STRING.
19+
# The function accepts STRING s as parameter.
20+
#
21+
22+
def timeConversion(s):
23+
return datetime.strptime(s, "%I:%M:%S%p").strftime("%H:%M:%S")
24+
25+
26+
if __name__ == '__main__':
27+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
28+
29+
s = input()
30+
31+
result = timeConversion(s)
32+
33+
fptr.write(result + '\n')
34+
35+
fptr.close()
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Problem solved: https://www.hackerrank.com/challenges/defaultdict-tutorial/problem?isFullScreen=true
3+
"""
4+
5+
from collections import defaultdict
6+
7+
n, m = map(int, input().split())
8+
group_a_dict = defaultdict(list)
9+
for index in range(n):
10+
group_a_dict[input()].append(index + 1)
11+
12+
d = defaultdict(list)
13+
14+
for _ in range(m):
15+
print(*group_a_dict[input()] or [-1])
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from itertools import permutations
2+
3+
sk = input().split()
4+
5+
s = sk[0]
6+
k = int(sk[1])
7+
8+
perms = permutations(s, k)
9+
perms_list = sorted([''.join(p) for p in perms])
10+
print('\n'.join(perms_list))

inputs.txt

+10,101-5
Large diffs are not rendered by default.

output.txt

+100
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)