nikhil19kekan
BAN USER
- 1of 1 vote
Answersl1=[1,2,3,4]
- nikhil19kekan in United States for Community Operations
l2=[1,3,6,7,null,null,null,null]
output: l2=[1,1,2,3,3,4,6,7]| Report Duplicate | Flag | PURGE
Facebook Software Developer - 1of 1 vote
Answersk=2, l=[1,2,3,4,5,6]
- nikhil19kekan in United States for Community Operations
output: l=[5,6,1,2,3,4]
In place O(1) space complexity| Report Duplicate | Flag | PURGE
Facebook Software Developer Arrays
you dont need to throw error when k is greater than array size, since its the number of rotations you want to perform
- nikhil19kekan March 04, 2019l1=[1,3,4,12,24,45]
l2=[1,2,3,4,5,6,7,None,None,None,None,None,None]
def merge_into_l2(l1,l2):
i=len(l1)-1
j=len(l2)-len(l1)-1
k=len(l2)-1
while(i>=0 and j>=0 and k>=0):
if(l1[i]>=l2[j]):
l2[k]=l1[i]
i-=1
k-=1
else:
l2[k]=l2[j]
j-=1
k-=1
return l2
print(merge_into_l2(l1,l2))
Thank You
-Nikhilkumar Kekan
def fun(temp,k,i,l):
#swap l[i] and temp
swap_val=l[i]
l[i]=temp
temp=l[i]
if(temp==None):
return l
else:
return fun(temp,k,(i+k)%len(l),l)
l=[8,3,2,[5,6,[9]],6]
count=1
ans=0
def fun(l,count,ans):
for e in l:
if(type(e) is list):
ans=fun(e,count*(count+1),ans)
else:
ans+=count*e
return ans
ans=fun(l,count,ans)
print(ans)
I think the input is not given as a string its rather list of lists
- nikhil19kekan November 30, 2018
- nikhil19kekan June 21, 2020