-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestions.py
More file actions
249 lines (179 loc) · 4.37 KB
/
Copy pathquestions.py
File metadata and controls
249 lines (179 loc) · 4.37 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
'''import math
def codingProblems(a1,a2):
a1 = int(a1/2)
a2 = int(a2/2)
return (a1+a2)*5
print(codingProblems(10,12))
def lcm(a,b):
m = max(a,b)
n = min(a,b)
while(1):
if m%a == 0 and m%b == 0:
return m
m += 1
return m
print(lcm(4,6))
def sum(a,b,c):
res = [a,b,c]
high = max(res)
return a+b+c - high + high*high
print(sum(1,5,5))
def dogYears(a1):
if (a1 == 1):
return a1*15
elif (a1==2):
return 9+15
elif (a1>=3 and a1<=6):
return 9+15+(a1-2)*4
else:
return 9+15+16+(a1-6)*5
print(dogYears(68))
n = int(input())
count = 0
for _ in range(n):
a,b = input().split( )
while(1):
lst1 = list(a)
lst2 = list(b)
if lst1 == lst2:
count +=1
print(count)
def lesser_of_two_evens(a,b):
if a%2 == 0 and b%2 == 0:
return min(a,b)
else:
return max(a,b)
def unique_list(arr):
return list(set(arr))
def get_pangram(a1):
alpha = "qwertyuiopasdfghjklzxcvbnm"
for char in alpha:
if char not in a1.lower():
print("It is not a Pangram")
break
else:
print("It is a Pangram")
break
return ""
print(get_pangram("go")
def animal_crackers(a1):
word1, word2 = a1.lower().split()
if word1[0] == word2[0]:
return True
return False
print(animal_crackers("Levelheaded Llama"))
print(animal_crackers("Crazy Kangaroo"))
def spy_game(a1):
sub = [0,0,7]
if sub in a1:
return True
return False
print(spy_game([1,2,4,0,0,7,5]))
def reverse_string(s):
return s[::-1]
print(reverse_string("Hello"))
def capitalize(s):
return ' '.join(word.capitalize() for word in s.split(' '))
print(capitalize("hello world! practice makes perfect"))
def remove(s,i):
string = list(s)
string.pop(i)
return ''.join(string)
print(remove("hello", 1))
def mulWord(s, n):
print(" ".join([s]*n))
mulWord('Hello', 3)
def isPrime(num):
if num <= 1:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
print(int(3**0.5 + 1))
print(int(15**0.5 + 1))
def mirrorDistance(num):
new = list(str(num))
new.reverse()
rev = int(''.join(new))
return abs(num - rev)
print(mirrorDistance(123))
from collections import Counter
def minCost(s,cost):
total = 0
new = []
counts = Counter(s)
most_common_char , frequency = counts.most_common(1)[0]
print(most_common_char[0])
for i in range(len(s)-1):
if s[i] != most_common_char[0]:
new.append(i)
else:
continue
print(new)
for j in new:
total += cost[j]
return total
print(minCost("aabaac",[1,2,3,4,1,10]))
def largestOddNumber(num):
"""
:type num: str
:rtype: str
"""
n = int(num)
largest_odd = None
curr = n
while curr > 0:
if curr%2 != 0:
if largest_odd is None or curr> largest_odd:
largest_odd = curr
curr //= 10
return largest_odd
print(largestOddNumber("10133890"))
def is_anagram(s,t):
arr_s = list(s)
arr_s.sort()
arr_t = list(t)
arr_t.sort()
if arr_s == arr_t:
return True
return False
print(is_anagram("cat","rat"))
def reverseWords(s):
"""
:type s: str
:rtype: str
"""
arr = s.split() # splits the string into words
print(arr)
arr.reverse() # reverses the list of words
return ' '.join(arr)
print(reverseWords("the sky is blue"))
def anagram(n):
cnt = 0
for _ in range(n):
a,b = map(int, input().split())
lst1 = list(str(a)).sort()
lst2 = list(str(b)).sort()
if lst1 == lst2:
cnt += 1
else:
continue
return cnt
print(anagram(3))
def missingNumber(nums):
"""
:type nums: List[int]
:rtype: int
"""
nums.sort()
if len(nums) == 1 :
if nums[-1]<= 0:
return nums[-1] +1
else:
return nums[-1] -1
for i in range(0,nums[-1]):
if nums[i] + 1 != nums[i+1]:
return nums[i]+1
return nums[-1]+1
print(missingNumber([1,2]))'''