1845. Seat Reservation Manager

1845. Seat Reservation Manager Design a system that manages the reservation state of n seats that are numbered from 1 to n. Implement the SeatManager class: SeatManager(int n) Initializes a SeatManager object that will manage n seats numbered from 1 to n. All seats are initially available. int reserve() Fetches the smallest-numbered unreserved seat, reserves it, and returns its number. void unreserve(int seatNumber) Unreserves the seat with the given seatNumber. 1 2 3 4 5 6 7 Example 1: Input ["SeatManager", "reserve", "reserve", "unreserve", "reserve", "reserve", "reserve", "reserve", "unreserve"] [[5], [], [], [2], [], [], [], [], [5]] Output [null, 1, 2, null, 2, 3, 4, 5, null] Explanation SeatManager seatManager = new SeatManager(5); // Initializes a SeatManager with 5 seats....

<span title='2021-05-08 00:00:00 +0000 UTC'>May 8, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

451. Sort Characters By Frequency

![https://leetcode.com/problems/sort-characters-by-frequency/] Given a string, sort it in decreasing order based on the frequency of characters. 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 Example 1: Input: "tree" Output: "eert" Explanation: 'e' appears twice while 'r' and 't' both appear once. So 'e' must appear before both 'r' and 't'....

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

767. Reorganize String

Given a string S, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same. If possible, output any possible result. If not possible, return the empty string. 1 2 3 4 5 6 7 8 9 Example 1: Input: S = "aab" Output: "aba" Example 2: Input: S = "aaab" Output: "" Note: S will consist of lowercase letters and have length in range [1, 500]....

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

1046. Last Stone Weight

![https://leetcode.com/problems/last-stone-weight/] We have a collection of stones, each stone has a positive integer weight. Each turn, we choose the two heaviest stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is: If x == y, both stones are totally destroyed; If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x....

<span title='2021-03-05 00:00:00 +0000 UTC'>March 5, 2021</span>&nbsp;·&nbsp;3 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 10 11 12 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....

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

347. Top K Frequent Elements

![https://leetcode.com/problems/top-k-frequent-elements/] Given a non-empty array of integers, return the k most frequent elements. 1 2 3 4 5 6 7 8 9 Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1] Note: You may assume k is always valid, 1 ≤ k ≤ number of unique elements. Your algorithm’s time complexity must be better than O(n log n), where n is the array’s size....

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

378. Kth Smallest Element in a Sorted Matrix

![https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/] Given an n x n matrix where each of the rows and columns are sorted in ascending order, return the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct element. 1 2 3 4 5 6 7 8 9 10 Example 1: Input: matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8 Output: 13 Explanation: The elements in the matrix are [1,5,9,10,11,12,13,13,15], and the 8th smallest number is 13 Example 2: Input: matrix = [[-5]], k = 1 Output: -5 Constraints:...

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

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