Leetcode 0020. Valid Parentheses

Posted on Mon 02 December 2024 in Leetcode • Tagged with stack, parentheses

Question Link : https://leetcode.com/problems/valid-parentheses/

Difficulty: Easy

Premium: False

Question

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if:

Open brackets must be closed by the same type of brackets. Open brackets must be closed …


Continue reading

Leetcode 0071. Simplify Path

Posted on Tue 11 April 2023 in Leetcode • Tagged with stack

Question Link : https://leetcode.com/problems/simplify-path/

Difficulty: Medium

Premium: False

Question

Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path. In a Unix-style file system, a period '.' refers …


Continue reading

Leetcode 2390. Removing Stars From a String

Posted on Mon 10 April 2023 in Leetcode • Tagged with stack

Question Link : https://leetcode.com/problems/removing-stars-from-a-string/

Difficulty: Medium

Premium: False

Question

You are given a string s, which contains stars *. In one operation, you can:

Choose a star in s. Remove the closest non-star character to its left, as well as remove the star itself.

Return the string after …


Continue reading

Leetcode 1472. Design Browser History

Posted on Sun 19 March 2023 in Leetcode • Tagged with stack

Question Link : https://leetcode.com/problems/design-browser-history/

Difficulty: Medium

Premium: False

Question

You have a browser of one tab where you start on the homepage and you can visit another url, get back in the history number of steps or move forward in the history number of steps. Implement the …


Continue reading

Leetcode 0232. Implement Queue using Stacks

Posted on Sat 14 January 2023 in Leetcode • Tagged with stack, queue

Question Link : https://leetcode.com/problems/implement-queue-using-stacks/

Difficulty: Easy

Premium: False

Question

Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class:

void push(int x) Pushes …


Continue reading

Leetcode 0150. Evaluate Reverse Polish Notation

Posted on Fri 16 December 2022 in Leetcode • Tagged with stack

Question Link : https://leetcode.com/problems/evaluate-reverse-polish-notation/

Difficulty: Medium

Premium: False

Question

Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, and /. Each operand may be an integer or another expression. Note that division between two integers should truncate toward zero. It is guaranteed that …


Continue reading

Leetcode 2414. Length of the Longest Alphabetical Continuous Substring

Posted on Thu 10 November 2022 in Leetcode • Tagged with pointers, stack

Question Link : https://leetcode.com/problems/length-of-the-longest-alphabetical-continuous-substring/

Difficulty: Medium

Question

An alphabetical continuous string is a string consisting of consecutive letters in the alphabet. In other words, it is any substring of the string "abcdefghijklmnopqrstuvwxyz".

For example, "abc" is an alphabetical continuous string, while "acb" and "za" are not.

Given …


Continue reading

Leetcode 1544. Make The String Great

Posted on Mon 07 November 2022 in Leetcode • Tagged with stack

Question Link : https://leetcode.com/problems/make-the-string-great/

Difficulty: Easy

Question

Given a string s of lower and upper case English letters. A good string is a string which doesn't have two adjacent characters s[i] and s[i + 1] where:

0 <= i <= s.length - 2 s[i] is a lower-case …


Continue reading

Leetcode 0946. Validate Stack Sequences

Posted on Tue 15 March 2022 in Leetcode • Tagged with stack, simulation, greedy

Question Link : https://leetcode.com/problems/validate-stack-sequences/

Difficulty: Medium

Question

Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise.   Example 1:

Input: pushed …


Continue reading

Leetcode 1249. Minimum Remove to Make Valid Parentheses

Posted on Mon 14 March 2022 in Leetcode • Tagged with stack, parentheses

Question Link : https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/

Difficulty: Medium

Question

Given a string s of '(' , ')' and lowercase English characters. Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string. Formally, a parentheses string …


Continue reading