Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion problems/house-robber-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/word-search-ii "Word Search II")

[Next >](https://github.com/openset/leetcode/tree/master/problems/shortest-palindrome "Shortest Palindrome")

## 213. House Robber II (Medium)

<p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are <strong>arranged in a circle.</strong> That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have security system connected and&nbsp;<b>it will automatically contact the police if two adjacent houses were broken into on the same night</b>.</p>
Expand Down Expand Up @@ -40,4 +44,7 @@
1. [Coin Path](https://github.com/openset/leetcode/tree/master/problems/coin-path) (Hard)

### Hints
1. Since House[1] and House[n] are adjacent, they cannot be robbed together. Therefore, the problem becomes to rob either House[1]-House[n-1] or House[2]-House[n], depending on which choice offers more money. Now the problem has degenerated to the <a href ="https://leetcode.com/problems/house-robber/description/">House Robber</a>, which is already been solved.
<details>
<summary>Hint 1</summary>
Since House[1] and House[n] are adjacent, they cannot be robbed together. Therefore, the problem becomes to rob either House[1]-House[n-1] or House[2]-House[n], depending on which choice offers more money. Now the problem has degenerated to the <a href ="https://leetcode.com/problems/house-robber/description/">House Robber</a>, which is already been solved.
</details>
9 changes: 8 additions & 1 deletion problems/investments-in-2016/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/find-customer-referee "Find Customer Referee")

[Next >](https://github.com/openset/leetcode/tree/master/problems/customer-placing-the-largest-number-of-orders "Customer Placing the Largest Number of Orders")

## 585. Investments in 2016 (Medium)

<p>Write a query to print the sum of all total investment values in 2016 (<b>TIV_2016</b>), to a scale of 2 decimal places, for all policy holders who meet the following criteria:</p>
Expand Down Expand Up @@ -60,4 +64,7 @@ And its location is the same with the third record, which makes the third record
So, the result is the sum of <b>TIV_2016</b> of the first and last record, which is 45.</pre>

### Hints
1. Make the (LAT, LON) a pair to represent the location information
<details>
<summary>Hint 1</summary>
Make the (LAT, LON) a pair to represent the location information
</details>
9 changes: 8 additions & 1 deletion problems/max-chunks-to-make-sorted-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/reorganize-string "Reorganize String")

[Next >](https://github.com/openset/leetcode/tree/master/problems/max-chunks-to-make-sorted "Max Chunks To Make Sorted")

## 768. Max Chunks To Make Sorted II (Hard)

<p><em>This question is the same as &quot;Max Chunks to Make Sorted&quot; except the integers of the given array are not necessarily distinct, the input array could be up to length <code>2000</code>, and the elements could be up to <code>10**8</code>.</em></p>
Expand Down Expand Up @@ -51,4 +55,7 @@ However, splitting into [2, 1], [3], [4], [4] is the highest number of chunks po
1. [Max Chunks To Make Sorted](https://github.com/openset/leetcode/tree/master/problems/max-chunks-to-make-sorted) (Medium)

### Hints
1. Each k for which some permutation of arr[:k] is equal to sorted(arr)[:k] is where we should cut each chunk.
<details>
<summary>Hint 1</summary>
Each k for which some permutation of arr[:k] is equal to sorted(arr)[:k] is where we should cut each chunk.
</details>
9 changes: 8 additions & 1 deletion problems/max-chunks-to-make-sorted/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/max-chunks-to-make-sorted-ii "Max Chunks To Make Sorted II")

[Next >](https://github.com/openset/leetcode/tree/master/problems/basic-calculator-iv "Basic Calculator IV")

## 769. Max Chunks To Make Sorted (Medium)

<p>Given an array <code>arr</code> that is a permutation of <code>[0, 1, ..., arr.length - 1]</code>, we split the array into some number of &quot;chunks&quot; (partitions), and individually sort each chunk.&nbsp; After concatenating them,&nbsp;the result equals the sorted array.</p>
Expand Down Expand Up @@ -47,4 +51,7 @@ However, splitting into [1, 0], [2], [3], [4] is the highest number of chunks po
1. [Max Chunks To Make Sorted II](https://github.com/openset/leetcode/tree/master/problems/max-chunks-to-make-sorted-ii) (Hard)

### Hints
1. The first chunk can be found as the smallest k for which A[:k+1] == [0, 1, 2, ...k]; then we repeat this process.
<details>
<summary>Hint 1</summary>
The first chunk can be found as the smallest k for which A[:k+1] == [0, 1, 2, ...k]; then we repeat this process.
</details>
9 changes: 8 additions & 1 deletion problems/min-cost-climbing-stairs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/prefix-and-suffix-search "Prefix and Suffix Search")

[Next >](https://github.com/openset/leetcode/tree/master/problems/largest-number-at-least-twice-of-others "Largest Number At Least Twice of Others")

## 746. Min Cost Climbing Stairs (Easy)

<p>
Expand Down Expand Up @@ -44,4 +48,7 @@ Once you pay the cost, you can either climb one or two steps. You need to find m
1. [Climbing Stairs](https://github.com/openset/leetcode/tree/master/problems/climbing-stairs) (Easy)

### Hints
1. Say f[i] is the final cost to climb to the top from step i. Then f[i] = cost[i] + min(f[i+1], f[i+2]).
<details>
<summary>Hint 1</summary>
Say f[i] is the final cost to climb to the top from step i. Then f[i] = cost[i] + min(f[i+1], f[i+2]).
</details>
9 changes: 8 additions & 1 deletion problems/minimum-ascii-delete-sum-for-two-strings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/number-of-distinct-islands-ii "Number of Distinct Islands II")

[Next >](https://github.com/openset/leetcode/tree/master/problems/subarray-product-less-than-k "Subarray Product Less Than K")

## 712. Minimum ASCII Delete Sum for Two Strings (Medium)

<p>Given two strings <code>s1, s2</code>, find the lowest ASCII sum of deleted characters to make two strings equal.</p>
Expand Down Expand Up @@ -44,4 +48,7 @@ If instead we turned both strings into "lee" or "eet", we would get answers of 4
1. [Delete Operation for Two Strings](https://github.com/openset/leetcode/tree/master/problems/delete-operation-for-two-strings) (Medium)

### Hints
1. Let dp(i, j) be the answer for inputs s1[i:] and s2[j:].
<details>
<summary>Hint 1</summary>
Let dp(i, j) be the answer for inputs s1[i:] and s2[j:].
</details>
9 changes: 8 additions & 1 deletion problems/monotone-increasing-digits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/sentence-similarity-ii "Sentence Similarity II")

[Next >](https://github.com/openset/leetcode/tree/master/problems/daily-temperatures "Daily Temperatures")

## 738. Monotone Increasing Digits (Medium)

<p>
Expand Down Expand Up @@ -45,4 +49,7 @@ Given a non-negative integer <code>N</code>, find the largest number that is les
1. [Remove K Digits](https://github.com/openset/leetcode/tree/master/problems/remove-k-digits) (Medium)

### Hints
1. Build the answer digit by digit, adding the largest possible one that would make the number still less than or equal to N.
<details>
<summary>Hint 1</summary>
Build the answer digit by digit, adding the largest possible one that would make the number still less than or equal to N.
</details>
9 changes: 8 additions & 1 deletion problems/my-calendar-i/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/self-dividing-numbers "Self Dividing Numbers")

[Next >](https://github.com/openset/leetcode/tree/master/problems/count-different-palindromic-subsequences "Count Different Palindromic Subsequences")

## 729. My Calendar I (Medium)

<p>
Expand Down Expand Up @@ -46,4 +50,7 @@ The third event can be booked, as the first event takes every time less than 20,
1. [My Calendar III](https://github.com/openset/leetcode/tree/master/problems/my-calendar-iii) (Hard)

### Hints
1. Store the events as a sorted list of intervals. If none of the events conflict, then the new event can be added.
<details>
<summary>Hint 1</summary>
Store the events as a sorted list of intervals. If none of the events conflict, then the new event can be added.
</details>
9 changes: 8 additions & 1 deletion problems/my-calendar-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/count-different-palindromic-subsequences "Count Different Palindromic Subsequences")

[Next >](https://github.com/openset/leetcode/tree/master/problems/my-calendar-iii "My Calendar III")

## 731. My Calendar II (Medium)

<p>
Expand Down Expand Up @@ -53,4 +57,7 @@ the time [40, 50) will be single booked, and the time [50, 55) will be double bo
1. [My Calendar III](https://github.com/openset/leetcode/tree/master/problems/my-calendar-iii) (Hard)

### Hints
1. Store two sorted lists of intervals: one list will be all times that are at least single booked, and another list will be all times that are definitely double booked. If none of the double bookings conflict, then the booking will succeed, and you should update your single and double bookings accordingly.
<details>
<summary>Hint 1</summary>
Store two sorted lists of intervals: one list will be all times that are at least single booked, and another list will be all times that are definitely double booked. If none of the double bookings conflict, then the booking will succeed, and you should update your single and double bookings accordingly.
</details>
9 changes: 8 additions & 1 deletion problems/my-calendar-iii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/my-calendar-ii "My Calendar II")

[Next >](https://github.com/openset/leetcode/tree/master/problems/flood-fill "Flood Fill")

## 732. My Calendar III (Hard)

<p>Implement a <code>MyCalendarThree</code> class to store your events. A new event can <b>always</b> be added.</p>
Expand Down Expand Up @@ -54,4 +58,7 @@ eg. [10, 20), [10, 40), and [5, 15) are still triple booked.
1. [My Calendar II](https://github.com/openset/leetcode/tree/master/problems/my-calendar-ii) (Medium)

### Hints
1. Treat each interval [start, end) as two events "start" and "end", and process them in sorted order.
<details>
<summary>Hint 1</summary>
Treat each interval [start, end) as two events "start" and "end", and process them in sorted order.
</details>
9 changes: 8 additions & 1 deletion problems/nim-game/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/word-pattern-ii "Word Pattern II")

[Next >](https://github.com/openset/leetcode/tree/master/problems/flip-game "Flip Game")

## 292. Nim Game (Easy)

<p>You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.</p>
Expand All @@ -27,4 +31,7 @@
1. [Flip Game II](https://github.com/openset/leetcode/tree/master/problems/flip-game-ii) (Medium)

### Hints
1. If there are 5 stones in the heap, could you figure out a way to remove the stones such that you will always be the winner?
<details>
<summary>Hint 1</summary>
If there are 5 stones in the heap, could you figure out a way to remove the stones such that you will always be the winner?
</details>
9 changes: 8 additions & 1 deletion problems/number-of-digit-one/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/implement-queue-using-stacks "Implement Queue using Stacks")

[Next >](https://github.com/openset/leetcode/tree/master/problems/palindrome-linked-list "Palindrome Linked List")

## 233. Number of Digit One (Hard)

<p>Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.</p>
Expand All @@ -24,4 +28,7 @@
1. [Factorial Trailing Zeroes](https://github.com/openset/leetcode/tree/master/problems/factorial-trailing-zeroes) (Easy)

### Hints
1. Beware of overflow.
<details>
<summary>Hint 1</summary>
Beware of overflow.
</details>
9 changes: 8 additions & 1 deletion problems/open-the-lock/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/ip-to-cidr "IP to CIDR")

[Next >](https://github.com/openset/leetcode/tree/master/problems/cracking-the-safe "Cracking the Safe")

## 752. Open the Lock (Medium)

<p>
Expand Down Expand Up @@ -65,4 +69,7 @@ We can't reach the target without getting stuck.
[[Breadth-first Search](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md)]

### Hints
1. We can think of this problem as a shortest path problem on a graph: there are `10000` nodes (strings `'0000'` to `'9999'`), and there is an edge between two nodes if they differ in one digit, that digit differs by 1 (wrapping around, so `'0'` and `'9'` differ by 1), and if *both* nodes are not in `deadends`.
<details>
<summary>Hint 1</summary>
We can think of this problem as a shortest path problem on a graph: there are `10000` nodes (strings `'0000'` to `'9999'`), and there is an edge between two nodes if they differ in one digit, that digit differs by 1 (wrapping around, so `'0'` and `'9'` differ by 1), and if *both* nodes are not in `deadends`.
</details>
19 changes: 16 additions & 3 deletions problems/out-of-boundary-paths/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/distribute-candies "Distribute Candies")

[Next >](https://github.com/openset/leetcode/tree/master/problems/employee-bonus "Employee Bonus")

## 576. Out of Boundary Paths (Medium)

<p>There is an <b>m</b> by <b>n</b> grid with a ball. Given the start coordinate <b>(i,j)</b> of the ball, you can move the ball to <b>adjacent</b> cell or cross the grid boundary in four directions (up, down, left, right). However, you can <b>at most</b> move <b>N</b> times. Find out the number of paths to move the ball out of grid boundary. The answer may be very large, return it after mod 10<sup>9</sup> + 7.</p>
Expand Down Expand Up @@ -47,6 +51,15 @@
1. [Knight Probability in Chessboard](https://github.com/openset/leetcode/tree/master/problems/knight-probability-in-chessboard) (Medium)

### Hints
1. WIll traversing every path is fesaible? There are many possible paths for a small matrix. Try to optimize it.
1. Can we use some space to store the number of paths and updating them after every move?
1. One obvious thing: ball will go out of boundary only by crossing it. Also, there is only one possible way ball can go out of boundary from boundary cell except corner cells. From corner cell ball can go out in two different ways. Can you use this thing to solve the problem?
<details>
<summary>Hint 1</summary>
WIll traversing every path is fesaible? There are many possible paths for a small matrix. Try to optimize it.
</details>
<details>
<summary>Hint 2</summary>
Can we use some space to store the number of paths and updating them after every move?
</details>
<details>
<summary>Hint 3</summary>
One obvious thing: ball will go out of boundary only by crossing it. Also, there is only one possible way ball can go out of boundary from boundary cell except corner cells. From corner cell ball can go out in two different ways. Can you use this thing to solve the problem?
</details>
9 changes: 8 additions & 1 deletion problems/palindrome-number/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/string-to-integer-atoi "String to Integer (atoi)")

[Next >](https://github.com/openset/leetcode/tree/master/problems/regular-expression-matching "Regular Expression Matching")

## 9. Palindrome Number (Easy)

<p>Determine whether an integer is a palindrome. An integer&nbsp;is&nbsp;a&nbsp;palindrome when it&nbsp;reads the same backward as forward.</p>
Expand Down Expand Up @@ -43,4 +47,7 @@
1. [Palindrome Linked List](https://github.com/openset/leetcode/tree/master/problems/palindrome-linked-list) (Easy)

### Hints
1. Beware of overflow when you reverse the integer.
<details>
<summary>Hint 1</summary>
Beware of overflow when you reverse the integer.
</details>
14 changes: 12 additions & 2 deletions problems/palindrome-permutation-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/palindrome-permutation "Palindrome Permutation")

[Next >](https://github.com/openset/leetcode/tree/master/problems/missing-number "Missing Number")

## 267. Palindrome Permutation II (Medium)

<p>Given a string <code>s</code>, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form.</p>
Expand All @@ -28,5 +32,11 @@
1. [Palindrome Permutation](https://github.com/openset/leetcode/tree/master/problems/palindrome-permutation) (Easy)

### Hints
1. If a palindromic permutation exists, we just need to generate the first half of the string.
1. To generate all distinct permutations of a (half of) string, use a similar approach from: <a href="/problems/permutations-ii">Permutations II</a> or <a href="/problems/next-permutation">Next Permutation</a>.
<details>
<summary>Hint 1</summary>
If a palindromic permutation exists, we just need to generate the first half of the string.
</details>
<details>
<summary>Hint 2</summary>
To generate all distinct permutations of a (half of) string, use a similar approach from: <a href="/problems/permutations-ii">Permutations II</a> or <a href="/problems/next-permutation">Next Permutation</a>.
</details>
Loading