703. Kth Largest Element in a Stream

Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. Implement KthLargest class: KthLargest(int k, int[] nums) Initializes the object with the integer k and the stream of integers nums. int add(int val) Returns the element representing the kth largest element in the stream. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Example 1: Input ["KthLargest", "add", "add", "add", "add", "add"] [[3, [4, 5, 8, 2]], [3], [5], [10], [9], [4]] Output [null, 4, 5, 5, 8, 8] Explanation KthLargest kthLargest = new KthLargest(3, [4, 5, 8, 2]); kthLargest....

<span title='2021-03-04 00:00:00 +0000 UTC'>March 4, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

1528. Shuffle String

![https://leetcode.com/problems/shuffle-string/] Given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string. Return the shuffled string. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Example 1: Input: s = "codeleet", indices = [4,5,6,7,0,2,1,3] Output: "leetcode" Explanation: As shown, "codeleet" becomes "leetcode" after shuffling....

<span title='2021-02-23 00:00:00 +0000 UTC'>February 23, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1598. Crawler Log Folder

![https://leetcode.com/problems/crawler-log-folder/] The Leetcode file system keeps a log each time some user performs a change folder operation. The operations are described below: “../” : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder). “./” : Remain in the same folder. “x/” : Move to the child folder named x (This folder is guaranteed to always exist). You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step....

<span title='2021-02-22 00:00:00 +0000 UTC'>February 22, 2021</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

1598. Crawler Log Folder

![https://leetcode.com/problems/crawler-log-folder/] The Leetcode file system keeps a log each time some user performs a change folder operation. The operations are described below: “../” : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder). “./” : Remain in the same folder. “x/” : Move to the child folder named x (This folder is guaranteed to always exist). You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step....

<span title='2021-02-22 00:00:00 +0000 UTC'>February 22, 2021</span>&nbsp;·&nbsp;4 min&nbsp;·&nbsp;volyx

1021. Remove Outermost Parentheses

![https://leetcode.com/problems/remove-outermost-parentheses/] A valid parentheses string is either empty (""), “(” + A + “)”, or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, “”, “()”, “(())()”, and “(()(()))” are all valid parentheses strings. A valid parentheses string S is primitive if it is nonempty, and there does not exist a way to split it into S = A+B, with A and B nonempty valid parentheses strings....

<span title='2021-02-20 00:00:00 +0000 UTC'>February 20, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

1047. Remove All Adjacent Duplicates In String

Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them. We repeatedly make duplicate removals on S until we no longer can. Return the final string after all such duplicate removals have been made. It is guaranteed the answer is unique. 1 2 3 4 5 6 Example 1: Input: "abbaca" Output: "ca" Explanation: For example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only possible move....

<span title='2021-02-20 00:00:00 +0000 UTC'>February 20, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

155. Min Stack

![https://leetcode.com/problems/min-stack/] Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element. getMin() – Retrieve the minimum element in the stack. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Example 1: Input ["MinStack","push","push","push","getMin","pop","top","getMin"] [[],[-2],[0],[-3],[],[],[],[]] Output [null,null,null,null,-3,null,0,-2] Explanation MinStack minStack = new MinStack(); minStack....

<span title='2021-02-20 00:00:00 +0000 UTC'>February 20, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

844. Backspace String Compare

![https://leetcode.com/problems/backspace-string-compare/] Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character. Note that after backspacing an empty text, the text will continue empty. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Example 1: Input: S = "ab#c", T = "ad#c" Output: true Explanation: Both S and T become "ac"....

<span title='2021-02-20 00:00:00 +0000 UTC'>February 20, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

682. Baseball Game

ou are keeping score for a baseball game with strange rules. The game consists of several rounds, where the scores of past rounds may affect future rounds’ scores. At the beginning of the game, you start with an empty record. You are given a list of strings ops, where ops[i] is the ith operation you must apply to the record and is one of the following: An integer x - Record a new score of x....

<span title='2021-02-19 00:00:00 +0000 UTC'>February 19, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

682. Baseball Game

![https://leetcode.com/problems/baseball-game/] You are keeping score for a baseball game with strange rules. The game consists of several rounds, where the scores of past rounds may affect future rounds’ scores. At the beginning of the game, you start with an empty record. You are given a list of strings ops, where ops[i] is the ith operation you must apply to the record and is one of the following: An integer x - Record a new score of x....

<span title='2021-02-16 00:00:00 +0000 UTC'>February 16, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

1496. Path Crossing

![https://leetcode.com/problems/path-crossing/] Given a string path, where path[i] = ‘N’, ‘S’, ‘E’ or ‘W’, each representing moving one unit north, south, east, or west, respectively. You start at the origin (0, 0) on a 2D plane and walk on the path specified by path. Return True if the path crosses itself at any point, that is, if at any time you are on a location you’ve previously visited. Return False otherwise....

<span title='2021-02-12 00:00:00 +0000 UTC'>February 12, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

1021. Remove Outermost Parentheses

![https://leetcode.com/problems/remove-outermost-parentheses/] A valid parentheses string is either empty (""), “(” + A + “)”, or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, “”, “()”, “(())()”, and “(()(()))” are all valid parentheses strings. A valid parentheses string S is primitive if it is nonempty, and there does not exist a way to split it into S = A+B, with A and B nonempty valid parentheses strings....

<span title='2021-01-26 00:00:00 +0000 UTC'>January 26, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

Buddy Strings

Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false. Swapping letters is defined as taking two indices i and j (0-indexed) such that i != j and swapping the characters at A[i] and A[j]. For example, swapping at indices 0 and 2 in “abcd” results in “cbad”. Example 1: Input: A = “ab”, B = “ba” Output: true Explanation: You can swap A[0] = ‘a’ and A[1] = ‘b’ to get “ba”, which is equal to B....

<span title='2020-10-28 00:00:00 +0000 UTC'>October 28, 2020</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

Sqrt(x)

Implement int sqrt(int x). Compute and return the square root of x, where x is guaranteed to be a non-negative integer. Since the return type is an integer, the decimal digits are truncated and only the integer part of the result is returned. Example 1: 1 2 Input: 4 Output: 2 Example 2: 1 2 Input: 8 Output: 2 Explanation: The square root of 8 is 2.82842…, and since the decimal part is truncated, 2 is returned....

<span title='2020-10-28 00:00:00 +0000 UTC'>October 28, 2020</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

Maximum Product of Three Numbers

Given an integer array, find three numbers whose product is maximum and output the maximum product. Example 1: 1 2 Input: [1,2,3] Output: 6 Example 2: 1 2 Input: [1,2,3,4] Output: 24 Note: The length of the given array will be in range [3,104] and all elements are in the range [-1000, 1000]. Multiplication of any three numbers in the input won’t exceed the range of 32-bit signed integer. Solution:...

<span title='2020-10-17 00:00:00 +0000 UTC'>October 17, 2020</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx