
PriorityQueue
文章平均质量分 73
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Smallest Range Covering Elements from K Lists
You haveklists of sorted integers innon-decreasingorder. Find thesmallestrange that includes at least one number from each of theklists.We define the range[a, b]is smaller than range[c, d]ifb - a < d - cora < cifb - a == d - c....原创 2022-05-20 14:07:47 · 382 阅读 · 0 评论 -
Maximum Number of Events That Can Be Attended
You are given an array ofeventswhereevents[i] = [startDayi, endDayi]. Every eventistarts atstartDayiand ends atendDayi.You can attend an eventiat any daydwherestartTimei<= d <= endTimei. You can only attend one event at any timed.R...原创 2022-03-16 01:57:49 · 362 阅读 · 0 评论 -
Minimum Time Difference
Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes difference between any two time-points in the list.Example 1:Input: timePoints = ["23:59","00:00"]Output: 1Example 2:Input: timePoints = ["00:00","23:59","0原创 2022-03-09 13:22:05 · 118 阅读 · 0 评论 -
Number of Orders in the Backlog
You are given a 2D integer arrayorders, where eachorders[i] = [pricei, amounti, orderTypei]denotes thatamountiorders have been placed of typeorderTypeiat the pricepricei. TheorderTypeiis:0if it is a batch ofbuyorders, or 1if it is a batch ...原创 2022-03-07 05:35:27 · 202 阅读 · 0 评论 -
Design A Leaderboard
Design a Leaderboard class, which has 3 functions:addScore(playerId, score): Update the leaderboard by addingscoreto the given player's score. If there is no player with such id in the leaderboard, add him to the leaderboard with the givenscore. top(...原创 2022-03-02 08:38:12 · 231 阅读 · 0 评论 -
Construct String With Repeat Limit
You are given a stringsand an integerrepeatLimit. Construct a new stringrepeatLimitedStringusing the characters ofssuch that no letter appearsmore thanrepeatLimittimesin a row. You donothave to use all characters froms.Returnthelexicograp...原创 2022-02-20 12:20:24 · 167 阅读 · 0 评论 -
Kth Largest in N Arrays
Find K-th largest element in N arrays.You can swap elements in the arrayExampleExample 1:Input:k=3, [[9,3,2,4,7],[1,2,3,4,8]]Output:7Explanation:the 3rd largest element is 7Example 2:Input:k = 2, [[9,3,2,4,8],[1,2,3,4,2]]Output:8Exp原创 2021-08-15 12:17:56 · 166 阅读 · 0 评论 -
Furthest Building You Can Reach
You are given an integer arrayheightsrepresenting the heights of buildings, somebricks, and someladders.You start your journey from building0and move to the next building by possibly using bricks or ladders.While moving from buildingito buildin...原创 2020-11-01 13:21:27 · 418 阅读 · 0 评论 -
Vertical Order Traversal of a Binary Tree
Given a binary tree, return thevertical ordertraversal of its nodesvalues.For each node at position(X, Y), its left and right children respectivelywill be at positions(X-1, Y-1)and(X+1, Y-1).Running a vertical line fromX = -infinitytoX = +in...原创 2020-08-10 13:02:13 · 228 阅读 · 0 评论 -
Top K Frequently Mentioned Keywords
Given a list ofreviews, a list ofkeywordsand an integerk. Find the top k keywords that appear most frequently in different reviews and in order of most to least frequently mentioned.The comparison of strings is case-insensitive. If keywords are mentio...原创 2020-07-23 05:42:34 · 292 阅读 · 0 评论 -
Minimum Number of Refueling Stops
A car travels from a starting position to a destination which istargetmiles east of the starting position.Along the way, there are gas stations. Eachstation[i]represents a gas station that isstation[i][0]miles east of the starting position, and ha...原创 2020-06-24 14:15:31 · 257 阅读 · 0 评论 -
Minimum Cost to Hire K Workers
There areNworkers. Thei-th worker has aquality[i]and a minimum wage expectationwage[i].Now we want to hire exactlyKworkers to form apaid group. When hiring a group of K workers, we must pay them according to the following rules:Every worker ...原创 2020-06-21 07:23:00 · 273 阅读 · 0 评论 -
Least Number of Unique Integers after K Removals
Given an array of integersarrand an integerk.Find theleast number of unique integersafter removingexactlykelements.Example 1:Input: arr = [5,5,4], k = 1Output: 1Explanation: Remove the single 4, only 5 is left.Example 2:Input: arr = [...原创 2020-06-14 12:43:48 · 259 阅读 · 0 评论 -
The k Strongest Values in an Array
Given an array of integersarrand an integerk.A valuearr[i]is said to be stronger than a valuearr[j]if|arr[i] - m| > |arr[j]- m|wheremis themedianof the array.If|arr[i] - m| == |arr[j] - m|, thenarr[i]is said to be stronger thanarr[j...原创 2020-06-07 12:30:45 · 193 阅读 · 0 评论 -
Divide Array in Sets of K Consecutive Numbers
Given an array of integersnumsand a positive integerk, find whether it's possible to divide this array intosets ofkconsecutive numbersReturnTrueif its possibleotherwisereturnFalse.Example 1:Input: nums = [1,2,3,3,4,4,5,6], k = 4Output: tr...原创 2020-05-25 13:34:01 · 202 阅读 · 0 评论 -
Robinhood 电面
Given a stream of incoming "buy" and "sell" orders (as lists of limit price, quantity, and side, like ["155", "3", "buy"]), determine the total quantity (or number of "shares") executed.A "buy" order can be executed if there is a corresponding "sell" ord原创 2020-05-19 07:12:40 · 2341 阅读 · 1 评论 -
Hand of Straights
Alice has ahandof cards, given as an array of integers.Now she wants to rearrange the cards into groups so that each group is sizeW, and consists ofWconsecutive cards.Returntrueif and only if she can.Example 1:Input: hand = [1,2,3,6,2,3,...原创 2020-05-11 01:12:04 · 272 阅读 · 0 评论 -
Task Scheduler
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks. Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could fi原创 2020-05-09 12:20:14 · 272 阅读 · 0 评论 -
Smallest Range Covering Elements from K Lists
You haveklists of sorted integers in ascending order. Find thesmallestrange that includes at least one number from each of theklists.We define the range [a,b] is smaller than range [c,d] ifb-...原创 2020-05-07 08:11:32 · 313 阅读 · 0 评论 -
My Calendar III
Implement aMyCalendarThreeclass to store your events. A new event canalwaysbe added.Your class will have one method,book(int start, int end). Formally, this represents a booking on the half ope...原创 2020-05-04 13:16:04 · 276 阅读 · 0 评论 -
My Calendar II
Implement aMyCalendarTwoclass to store your events. A new event can be added if adding the event will not cause atriplebooking.Your class will have one method,book(int start, int end). Formally...原创 2020-05-04 12:59:18 · 273 阅读 · 0 评论 -
My Calendar I
Implement aMyCalendarclass to store your events. A new event can be added if adding the event will not cause a double booking.Your class will have the method,book(int start, int end). Formally, t...原创 2020-05-04 01:54:17 · 352 阅读 · 0 评论 -
Employee Free Time
We are given a listscheduleof employees, which represents the working time for each employee.Each employee has a list of non-overlappingIntervals, and these intervals are in sorted order.Return...原创 2020-05-02 05:49:24 · 367 阅读 · 0 评论 -
Course Schedule III
There arendifferent online courses numbered from1ton. Each course has some duration(course length)tand closed ondthday. A course should be takencontinuouslyfortdays and must be finished b...原创 2020-04-30 10:16:30 · 250 阅读 · 0 评论 -
Distant Barcodes
In a warehouse, there is a row of barcodes, where thei-th barcode isbarcodes[i].Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed ...原创 2020-04-26 15:01:43 · 203 阅读 · 0 评论 -
Rearrange String k Distance Apart
Given a non-empty stringsand an integerk, rearrange the string such that the same characters are at least distancekfrom each other.All input strings are given in lowercase letters. If it is not...原创 2020-04-26 12:07:26 · 413 阅读 · 0 评论 -
Reorganize String
Given a stringS, 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...原创 2020-04-26 11:25:12 · 326 阅读 · 0 评论 -
Minimum Cost to Connect Sticks
You have somestickswithpositive integer lengths.You can connect any two sticks of lengthsXandYinto one stickby paying a cost ofX + Y. You perform this action until there is one stick remai...原创 2020-03-29 12:06:59 · 206 阅读 · 0 评论 -
Rotting Oranges
In a given grid, each cell can have one of threevalues:the value0representing an empty cell; the value1representing a fresh orange; the value2representing a rotten orange.Every minute, any...原创 2020-03-22 08:55:16 · 418 阅读 · 0 评论 -
High Five
Given a list of scores of different students, return the average score of each student'stop five scoresinthe order of each student's id.Each entryitems[i]hasitems[i][0]the student's id, andi...原创 2020-03-09 14:02:03 · 270 阅读 · 0 评论 -
Consistent Hashing
A general database method for performing a horizontal shard is to take the id against the total number of database servers n and then to find out which machine it is on. The downside of this approach ...原创 2020-01-21 09:16:43 · 221 阅读 · 0 评论 -
Find Kth题目类型总结 (quick Select 类型总结)
找第k大或者第k小的题型,也是经常面试考,这里做个总结;首先quick select算法的模板要倒背如流,这个是通过quick sort里面提炼得到的算法;两个while一个if,condition相同;后面再递归Kth Smallest Numbers in Unsorted Array找到一个无序数组中第K小的数Example样例 1:输入: [3, 4, 1, 2,...原创 2020-01-07 15:01:55 · 2113 阅读 · 0 评论 -
Kth Largest Element II
Find K-th largest element in an array. and N is much larger than k. Note that it is the kth largest element in the sorted order, not the kth distinct element.ExampleExample 1:Input:[9,3,2,4,8],...原创 2020-01-02 13:27:54 · 259 阅读 · 0 评论 -
Top K Largest Numbers II
Implement a data structure, provide two interfaces:add(number). Add a new number in the data structure. topk(). Return the topklargest numbers in this data structure.kis given when we create th...原创 2020-01-02 08:45:12 · 225 阅读 · 0 评论 -
Sliding Window Median
Given an array of n integer, and a moving window(size k), move the window at each iteration from the start of the array, find the median of the element inside the window at each moving. (If there are ...原创 2019-11-30 09:20:06 · 310 阅读 · 0 评论 -
Median of K Sorted Arrays
There areksorted arraysnums. Find the median of the givenksorted arrays.ExampleExample 1:Input:[[1],[2],[3]]Output:2.00Example 2:Input:[[1,1,2],[2,4,8],[3,7,10,20]]Output:3.50...原创 2019-11-27 08:58:03 · 304 阅读 · 0 评论 -
Kth Smallest Sum In Two Sorted Arrays
Given two integer arrays sorted in ascending order and an integer k. Definesum = a + b, whereais an element from the first array andbis an element from the second one. Find thekth smallest sum o...原创 2019-11-25 04:56:55 · 654 阅读 · 0 评论 -
Trapping Rain Water II
Givennxmnon-negative integers representing an elevation map 2d where the area of each cell is1x1, compute how much water it is able to trap after raining.ExampleExample 1:Given `5*4...原创 2019-11-20 01:38:18 · 197 阅读 · 0 评论 -
Ugly Number II
Ugly number is a number that only have prime factors2,3and5.Design an algorithm to find thenth ugly number. The first 10 ugly numbers are1, 2, 3, 4, 5, 6, 8, 9, 10, 12...ExampleExample 1:...原创 2019-11-16 10:27:32 · 157 阅读 · 0 评论 -
Top K Largest Numbers
Given an integer array, find the topklargest numbers in it.ExampleExample1Input: [3, 10, 1000, -99, 4, 100] and k = 3Output: [1000, 100, 10]Example2Input: [8, 7, 6, 5, 4, 3, 2, 1] and ...原创 2019-11-15 14:56:09 · 209 阅读 · 0 评论