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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Stacks
  4. Maximum Element
  5. Discussions

Maximum Element

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • peddireddysriji1
    4 months ago+ 1 comment

    PY3

    def getMax(operations):
        stack = [0]
        my = []
        for i in operations:
            if int(i[0]) == 1:
                n = int(i[2:])
                stack.append(max(n,stack[-1]))
            elif int(i[0]) == 2:
                if stack:
                    stack.pop()
            else:
                my.append(stack[-1])
        return my
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy