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.
I also tried by using maxstack..but i coudn't pass test-6,7,11,10... Help me... check it.
intmain(){longlongintstack[100000],max[100000],x;longintN,top=-1,topm=0;intq;scanf("%ld",&N);for(longinti=0;i<N;i++)max[i]=0;for(longinti=0;i<N;i++){scanf("%d",&q);switch(q){case1:scanf(" %lld",&x);if(max[topm]<x){max[++topm]=x;}stack[++top]=x;break;case2:if(max[topm]==stack[top])--topm;--top;break;case3:printf("%lld\n",max[topm]);break;}}/* Enter your code here. Read input from STDIN. Print output to STDOUT */return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →
I also tried by using maxstack..but i coudn't pass test-6,7,11,10... Help me... check it.