Solution in Python 3

def separateNumbers(s):    if len(s)==1:
print("NO")
return
for i in range(1, len(s)//2+1): genstr = s[:i]
prev = int(genstr)
while len(genstr) < len(s): next = prev+1
genstr+=str(next)
prev = next
if genstr == s:
print("YES", s[:i])
return
print("NO")

Explanation



Solution in Python 3

from collections import defaultdict
n, m = map(int, input().split())
d = defaultdict(list)for i in range(n):
d[input()].append(i+1)
for j in range(m):
s = input()
if s in d:
print(*d[s])
else:
print(-1)

Explanation


Solution in Python 3

from collections import Counterdef pickingNumbers(a):
countNums = Counter(a)
maxnum=0
for i in range(1, 100):
maxnum = max(maxnum, countNums[i]+countNums[i+1])

return maxnum

Explanation


Solution in Python 3

def sockMerchant(n, ar):
countOfSocks = []
for sock in set(ar):
countOfSocks.append(ar.count(sock))
return sum([i//2 for i in countOfSocks])

Explanation


Solution in Python 3

def dayOfProgrammer(year):
if year < 1700 or year > 2700:
return

elif year==1918:
return '26.09.1918'

elif year < 1918:
if year%4==0:
return '12.09.'+str(year)

else:
return '13.09.'+str(year)

elif year > 1918:
if year%400==0 or year%4==0 and year%100!=0:
return '12.09.'+str(year) …

Solution in Python 3

def beautifulDays(i, j, k):
beautifulDays = 0
for day in range(i, j+1):
rev = int(str(day)[::-1])
if abs(rev-day)%k==0:
beautifulDays+=1

return beautifulDays

Explanation


Solution in Python 3

def acmTeam(topic):
ans = []
for i in range(n):
for j in range(i+1, n):
know=0
for a,b in zip(topic[i], topic[j]):
if a=='1' or b=='1':
know+=1
ans.append(know)

return [max(ans), ans.count(max(ans))]

Explanation


Solution in Python 3

def kangaroo(x1, v1, x2, v2):
if x1 < x2 and v1 < v2:
return 'NO'
else:
if v1!=v2 and (x2-x1)%(v2-v1)==0:
return 'YES'
else:
return 'NO'

Explanation in Python 3


Shounak Lohokare

pretending to teach is one of the best way to learn.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store