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

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