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.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'poisonousPlants' function below.## The function is expected to return an INTEGER.# The function accepts INTEGER_ARRAY p as parameter.#defpoisonousPlants(p):# Write your code heremday,s=0,[]foriinp:ifnot(s)ori<=s[0][0]:s=[[i,0]]elifi>s[-1][0]:s.append([i,1])else:d=1whilesandi<=s[-1][0]:d=max(d,s.pop()[1]+1)s.append([i,d])mday=max(mday,s[-1][1])returnmdayif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')n=int(input().strip())p=list(map(int,input().rstrip().split()))result=poisonousPlants(p)fptr.write(str(result)+'\n')fptr.close()
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 →
Python3 Solution: