Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungThe Indie Dev Visibility Playbook: From Zero Users to Your First 100(21.09.2026 um 00:08 Uhr)
Sichere ProgrammierungBase, Chat and Reasoning Models: How Are They Different?(21.09.2026 um 00:09 Uhr)
Sichere ProgrammierungHexfield Deck is for Kanban lovers and Markdown believers(21.09.2026 um 00:20 Uhr)
Sichere ProgrammierungPermissions and Authorisation: A Practical Playbook(21.09.2026 um 00:21 Uhr)
Linux Tipps & Hardeningfilet | Terminal File Manager(20.09.2026 um 21:03 Uhr)
Linux Tipps & HardeningLooking for feedback on my Linux Distro(20.09.2026 um 21:03 Uhr)
Sichere ProgrammierungThe Indie Dev Visibility Playbook: From Zero Users to Your First 100(21.09.2026 um 00:08 Uhr)
Sichere ProgrammierungBase, Chat and Reasoning Models: How Are They Different?(21.09.2026 um 00:09 Uhr)
Sichere ProgrammierungHexfield Deck is for Kanban lovers and Markdown believers(21.09.2026 um 00:20 Uhr)
Sichere ProgrammierungPermissions and Authorisation: A Practical Playbook(21.09.2026 um 00:21 Uhr)
Linux Tipps & Hardeningfilet | Terminal File Manager(20.09.2026 um 21:03 Uhr)
Linux Tipps & HardeningLooking for feedback on my Linux Distro(20.09.2026 um 21:03 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Leetcode Solution #6

Reagiere als Erste:r — dein Feedback zählt!

1. Min Stack

The Problem

Start by reading the description of the problem,

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.

Implement the MinStack class:

  • MinStack() initializes the stack object.

  • void push(int val) pushes the element val onto the stack.

  • void pop() removes the element on the top of the stack.

  • int top() gets the top element of the stack.

  • int getMin() retrieves the minimum element in the stack.

You must implement a solution with O(1) time complexity for each function.

It is a leetcode medium question but very easy to attempt.

Refer the example for better understanding,

Image description

Approach

Our approach for this question is going to be pretty straightforward, we don't need to do anything special in this question we will just apply our basic knowledge of stack and complete the given functions.

Solution

Image description

Image description

We have implemented the solution in following ways:

  1. Initialise two stacks s1 and min, s1 will store all values and min stack will have the minimum value.

  2. MinStack will be empty as it will not do anything specific here.

  3. In push function, push the value in main stack(s1), check if min stack is empty or value is less than or equal to current minimum value. If condition is true, it means value is new minimum, so it should be added to min stack.

  4. For pop function ensure that s1 is not empty, check if top value of s1 is equal to top value of min. If so, means that we have to pop top value of min stack.

  5. Pop top value from s1.

  6. For top function, return top value of s1 stack.

  7. For getMin function, return top value of min stack.

2. Evaluate Reverse Polish Notation

The Problem

You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.

Evaluate the expression. Return an integer that represents the value of the expression.

Note that:

  • The valid operators are '+', '-', '*', and '/'.

  • Each operand may be an integer or another expression.

  • The division between two integers always truncates toward zero.

  • There will not be any division by zero.

  • The input represents a valid arithmetic expression in a reverse
    polish notation.

  • The answer and all the intermediate calculations can be
    represented in a 32-bit integer.

This question is also very basic and is rated medium on leetcode, It is very basic question we just have to evaluate postfix notation.

Refer the examples given below for better understanding

Image description

Approaches

  1. Iterate over all characters one by one.

  2. If character is operand push it in the stack.

  3. If character is operator pop two elements from start and perform operation.

Solution

Image description

Image description

We have achieved this solution by following ways:

  1. Initialise a stack to store the result.

  2. Iterate over the tokens vector.

  3. Check if first character of token is digit, then check if it has atleast 2 characters and negative and second character must be digit.

  4. If any of above is true convert string to int and push it in stack.

  5. Else if the character is an operator, There are two operands at top of stack value 1 and value 2.

  6. Since token is an operator now based on operator check the case and push the value.

  7. The final result is at top of the stack.

I hope the solutions I have provided are understandable and explanations are easy to understand.

Thank You

You can connect with me on Linkedin

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Leetcode Solution #6

Thematisch verwandte Begriffe: Leetcode, Solution · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94084 | Suricata before 8.0.7 has an Http2ThreadMultiBuf use-after-free when a t…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick