-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterview01_Warm-up_Challenges
127 lines (97 loc) · 2.32 KB
/
Interview01_Warm-up_Challenges
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
## Interview Preparation Kit
## Warm-up Challenges
## Sock Merchant
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the sockMerchant function below.
from collections import Counter
def sockMerchant(n, ar):
total = 0
for value in Counter(ar).values():
total += value//2
return total
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
ar = list(map(int, input().rstrip().split()))
result = sockMerchant(n, ar)
fptr.write(str(result) + '\n')
fptr.close()
## Counting Valleys
import math
import os
import random
import re
import sys
# Complete the countingValleys function below.
def countingValleys(n, s):
altitude = 0
valleys = 0
for letter in s:
if letter == 'U':
altitude += 1
else:
altitude -= 1
if altitude == -1:
valleys += 1
return valleys
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
s = input()
result = countingValleys(n, s)
fptr.write(str(result) + '\n')
fptr.close()
## Jumping on the Clouds
import math
import os
import random
import re
import sys
# Complete the jumpingOnClouds function below.
def jumpingOnClouds(c):
jump = 0
i = 1
while i < len(c):
if i != len(c)-1 and c[i+1] == 0:
jump += 1
i += 2
elif c[i] == 0:
jump += 1
i += 1
return jump
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
c = list(map(int, input().rstrip().split()))
result = jumpingOnClouds(c)
fptr.write(str(result) + '\n')
fptr.close()
# 0 0 0 0 1 0
# 0 0 0 1 0 0
## Repeated String
import math
import os
import random
import re
import sys
# Complete the repeatedString function below.
def repeatedString(s, n):
count = s.count('a')
full_str = n//len(s)
remainder = n%len(s)
total = count*full_str + s[:remainder].count('a')
return total
# return (s.count("a") * (n // len(s)) + s[:n % len(s)].count("a"))
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
n = int(input())
result = repeatedString(s, n)
fptr.write(str(result) + '\n')
fptr.close()
## end ##