1090. Largest Values From Labels

![https://leetcode.com/problems/largest-values-from-labels/] We have a set of items: the i-th item has value values[i] and label labels[i]. Then, we choose a subset S of these items, such that: |S| <= num_wanted For every label L, the number of items in S with label L is <= use_limit. Return the largest possible sum of the subset S. 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: values = [5,4,3,2,1], labels = [1,1,2,2,3], num_wanted = 3, use_limit = 1 Output: 9 Explanation: The subset chosen is the first, third, and fifth item....

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

240. Search a 2D Matrix II

![https://leetcode.com/problems/search-a-2d-matrix-ii/] Write an efficient algorithm that searches for a target value in an m x n integer matrix. The matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom. 1 2 3 4 Example 1: Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5 Output: true 1 2 3 4 Example 2: Input: matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20 Output: false Constraints:...

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

1637. Widest Vertical Area Between Two Points Containing No Points

![https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points/] Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area. A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width. Note that points on the edge of a vertical area are not considered included in the area....

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

973. K Closest Points to Origin

![https://leetcode.com/problems/k-closest-points-to-origin/] We have a list of points on the plane. Find the K closest points to the origin (0, 0). (Here, the distance between two points on a plane is the Euclidean distance.) You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in.) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Example 1: Input: points = [[1,3],[-2,2]], K = 1 Output: [[-2,2]] Explanation: The distance between (1, 3) and the origin is sqrt(10)....

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

169. Majority Element

![https://leetcode.com/problems/majority-element/] Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. 1 2 3 4 5 6 7 8 9 Example 1: Input: nums = [3,2,3] Output: 3 Example 2: Input: nums = [2,2,1,1,1,2,2] Output: 2 Constraints: n == nums.length 1 <= n <= 5 * 104 -231 <= nums[i] <= 231 - 1 Follow-up: Could you solve the problem in linear time and in O(1) space?...

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

215. Kth Largest Element in an Array

![https://leetcode.com/problems/kth-largest-element-in-an-array/] Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. 1 2 3 4 5 6 7 8 9 Example 1: Input: [3,2,1,5,6,4] and k = 2 Output: 5 Example 2: Input: [3,2,3,1,2,4,5,5,6] and k = 4 Output: 4 Note: You may assume k is always valid, 1 ≤ k ≤ array’s length. 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 class Solution { public int findKthLargest(int[] nums, int k) { int lo = 0; int hi = nums....

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

1319. Number of Operations to Make Network Connected

![https://leetcode.com/problems/remove-outermost-parentheses/] There are n computers numbered from 0 to n-1 connected by ethernet cables connections forming a network where connections[i] = [a, b] represents a connection between computers a and b. Any computer can reach any other computer directly or indirectly through the network. Given an initial computer network connections. You can extract certain cables between two directly connected computers, and place them between any pair of disconnected computers to make them directly connected....

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

150. Evaluate Reverse Polish Notation

![https://leetcode.com/problems/evaluate-reverse-polish-notation/] Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Note: Division between two integers should truncate toward zero. The given RPN expression is always valid. That means the expression would always evaluate to a result and there won’t be any divide by zero operation. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Example 1: Input: ["2", "1", "+", "3", "*"] Output: 9 Explanation: ((2 + 1) * 3) = 9 Example 2: Input: ["4", "13", "5", "/", "+"] Output: 6 Explanation: (4 + (13 / 5)) = 6 Example 3: Input: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"] Output: 22 Explanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5 = ((10 * (6 / (12 * -11))) + 17) + 5 = ((10 * (6 / -132)) + 17) + 5 = ((10 * 0) + 17) + 5 = (0 + 17) + 5 = 17 + 5 = 22 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 27 28 29 30 31 32 33 34 35 class Solution { public int evalRPN(String[] tokens) { int[] stack = new int[tokens....

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

1209. Remove All Adjacent Duplicates in String II

![https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii/] Given a string s, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them causing the left and the right side of the deleted substring to concatenate together. We repeatedly make k duplicate removals on s until we no longer can. Return the final string after all such duplicate removals have been made. It is guaranteed that the answer is unique. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Example 1: Input: s = "abcd", k = 2 Output: "abcd" Explanation: There's nothing to delete....

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

227. Basic Calculator II

![https://leetcode.com/problems/basic-calculator-ii/] Given a string s which represents an expression, evaluate this expression and return its value. The integer division should truncate toward zero. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Example 1: Input: s = "3+2*2" Output: 7 Example 2: Input: s = " 3/2 " Output: 1 Example 3: Input: s = " 3+5 / 2 " Output: 5 Constraints: 1 <= s....

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

921. Minimum Add to Make Parentheses Valid

![https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/] 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 is valid if and only if: It is the empty string, contains only lowercase characters, or It can be written as AB (A concatenated with B), where A and B are valid strings, or It can be written as (A), where A is a valid string....

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

128. Longest Consecutive Sequence

![https://leetcode.com/problems/longest-consecutive-sequence/] Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. 1 2 3 4 5 6 7 8 9 10 Example 1: Input: nums = [100,4,200,1,3,2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4. Example 2: Input: nums = [0,3,7,2,5,8,4,6,0,1] Output: 9 Constraints: 0 <= nums.length <= 104 -109 <= nums[i] <= 109 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 class Solution { public int longestConsecutive(int[] nums) { Map<Integer, Integer> valueToIndex = new HashMap<>(); UF uf = new UF(nums....

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

721. Accounts Merge

![https://leetcode.com/problems/accounts-merge/] Given a list accounts, each element accounts[i] is a list of strings, where the first element accounts[i][0] is a name, and the rest of the elements are emails representing emails of the account. Now, we would like to merge these accounts. Two accounts definitely belong to the same person if there is some email that is common to both accounts. Note that even if two accounts have the same name, they may belong to different people as people could have the same name....

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

1202. Smallest String With Swaps

![https://leetcode.com/problems/smallest-string-with-swaps/] You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. You can swap the characters at any pair of indices in the given pairs any number of times. Return the lexicographically smallest string that s can be changed to after using the swaps. 1 2 3 4 5 6 7 Example 1: Input: s = "dcab", pairs = [[0,3],[1,2]] Output: "bacd" Explaination: Swap s[0] and s[3], s = "bcad" Swap s[1] and s[2], s = "bacd" 1 2 3 4 5 6 7 8 Example 2: Input: s = "dcab", pairs = [[0,3],[1,2],[0,2]] Output: "abcd" Explaination: Swap s[0] and s[3], s = "bcad" Swap s[0] and s[2], s = "acbd" Swap s[1] and s[2], s = "abcd" 1 2 3 4 5 6 7 8 Example 3: Input: s = "cba", pairs = [[0,1],[1,2]] Output: "abc" Explaination: Swap s[0] and s[1], s = "bca" Swap s[1] and s[2], s = "bac" Swap s[0] and s[1], s = "abc" Constraints:...

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

785. Is Graph Bipartite?

![https://leetcode.com/problems/is-graph-bipartite/] Given an undirected graph, return true if and only if it is bipartite. Recall that a graph is bipartite if we can split its set of nodes into two independent subsets A and B, such that every edge in the graph has one node in A and another node in B. The graph is given in the following form: graph[i] is a list of indexes j for which the edge between nodes i and j exists....

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