We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defpoisonousPlants(p):# Write your code hereday=0stack=[]foriinrange(len(p)):ifi==0:stack.append((p[i],0))elifp[i]>stack[0][0]:ifp[i]>stack[-1][0]:stack.append((p[i],1))else:ld=1whilestackandp[i]<=stack[-1][0]:ld=max(ld,stack[-1][1]+1)stack.pop()stack.append((p[i],ld))else:stack=[(p[i],0)]day=max(day,stack[-1][1])#print("Elements of stack are: ", stack)returnday
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Poisonous Plants
You are viewing a single comment's thread. Return to all comments →
Python 3 Soln: