diff --git a/problems/house-robber-ii/README.md b/problems/house-robber-ii/README.md index f97e28fb9..2c6e50a01 100644 --- a/problems/house-robber-ii/README.md +++ b/problems/house-robber-ii/README.md @@ -5,6 +5,10 @@ +[< 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)

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 arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

@@ -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 House Robber, which is already been solved. +
+Hint 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 House Robber, which is already been solved. +
diff --git a/problems/investments-in-2016/README.md b/problems/investments-in-2016/README.md index d2f2825b3..6ba2f13f5 100644 --- a/problems/investments-in-2016/README.md +++ b/problems/investments-in-2016/README.md @@ -5,6 +5,10 @@ +[< 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)

Write a query to print the sum of all total investment values in 2016 (TIV_2016), to a scale of 2 decimal places, for all policy holders who meet the following criteria:

@@ -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 TIV_2016 of the first and last record, which is 45. ### Hints - 1. Make the (LAT, LON) a pair to represent the location information +
+Hint 1 +Make the (LAT, LON) a pair to represent the location information +
diff --git a/problems/max-chunks-to-make-sorted-ii/README.md b/problems/max-chunks-to-make-sorted-ii/README.md index dbffe56c8..6b985ec51 100644 --- a/problems/max-chunks-to-make-sorted-ii/README.md +++ b/problems/max-chunks-to-make-sorted-ii/README.md @@ -5,6 +5,10 @@ +[< 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)

This question is the same as "Max Chunks to Make Sorted" except the integers of the given array are not necessarily distinct, the input array could be up to length 2000, and the elements could be up to 10**8.

@@ -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. +
+Hint 1 +Each k for which some permutation of arr[:k] is equal to sorted(arr)[:k] is where we should cut each chunk. +
diff --git a/problems/max-chunks-to-make-sorted/README.md b/problems/max-chunks-to-make-sorted/README.md index 2067828c8..11a8e0e41 100644 --- a/problems/max-chunks-to-make-sorted/README.md +++ b/problems/max-chunks-to-make-sorted/README.md @@ -5,6 +5,10 @@ +[< 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)

Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into some number of "chunks" (partitions), and individually sort each chunk.  After concatenating them, the result equals the sorted array.

@@ -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. +
+Hint 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. +
diff --git a/problems/min-cost-climbing-stairs/README.md b/problems/min-cost-climbing-stairs/README.md index 1be159514..98974a510 100644 --- a/problems/min-cost-climbing-stairs/README.md +++ b/problems/min-cost-climbing-stairs/README.md @@ -5,6 +5,10 @@ +[< 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)

@@ -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]). +

+Hint 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]). +
diff --git a/problems/minimum-ascii-delete-sum-for-two-strings/README.md b/problems/minimum-ascii-delete-sum-for-two-strings/README.md index a01fe5b59..c2c8c6c6b 100644 --- a/problems/minimum-ascii-delete-sum-for-two-strings/README.md +++ b/problems/minimum-ascii-delete-sum-for-two-strings/README.md @@ -5,6 +5,10 @@ +[< 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)

Given two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.

@@ -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:]. +
+Hint 1 +Let dp(i, j) be the answer for inputs s1[i:] and s2[j:]. +
diff --git a/problems/monotone-increasing-digits/README.md b/problems/monotone-increasing-digits/README.md index e15f688bb..a08195536 100644 --- a/problems/monotone-increasing-digits/README.md +++ b/problems/monotone-increasing-digits/README.md @@ -5,6 +5,10 @@ +[< 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)

@@ -45,4 +49,7 @@ Given a non-negative integer N, 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. +

+Hint 1 +Build the answer digit by digit, adding the largest possible one that would make the number still less than or equal to N. +
diff --git a/problems/my-calendar-i/README.md b/problems/my-calendar-i/README.md index 4f16613de..b531b3bc4 100644 --- a/problems/my-calendar-i/README.md +++ b/problems/my-calendar-i/README.md @@ -5,6 +5,10 @@ +[< 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)

@@ -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. +

+Hint 1 +Store the events as a sorted list of intervals. If none of the events conflict, then the new event can be added. +
diff --git a/problems/my-calendar-ii/README.md b/problems/my-calendar-ii/README.md index 8b9692405..b7d531bf3 100644 --- a/problems/my-calendar-ii/README.md +++ b/problems/my-calendar-ii/README.md @@ -5,6 +5,10 @@ +[< 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)

@@ -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. +

+Hint 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. +
diff --git a/problems/my-calendar-iii/README.md b/problems/my-calendar-iii/README.md index 62e6ab9b0..19684d6c1 100644 --- a/problems/my-calendar-iii/README.md +++ b/problems/my-calendar-iii/README.md @@ -5,6 +5,10 @@ +[< 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)

Implement a MyCalendarThree class to store your events. A new event can always be added.

@@ -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. +
+Hint 1 +Treat each interval [start, end) as two events "start" and "end", and process them in sorted order. +
diff --git a/problems/nim-game/README.md b/problems/nim-game/README.md index a91f8f62e..e305066e0 100644 --- a/problems/nim-game/README.md +++ b/problems/nim-game/README.md @@ -5,6 +5,10 @@ +[< 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)

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.

@@ -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? +
+Hint 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? +
diff --git a/problems/number-of-digit-one/README.md b/problems/number-of-digit-one/README.md index 0a51527f3..62719a3cf 100644 --- a/problems/number-of-digit-one/README.md +++ b/problems/number-of-digit-one/README.md @@ -5,6 +5,10 @@ +[< 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)

Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.

@@ -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. +
+Hint 1 +Beware of overflow. +
diff --git a/problems/open-the-lock/README.md b/problems/open-the-lock/README.md index ef4335047..7ade4bd48 100644 --- a/problems/open-the-lock/README.md +++ b/problems/open-the-lock/README.md @@ -5,6 +5,10 @@ +[< 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)

@@ -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`. +

+Hint 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`. +
diff --git a/problems/out-of-boundary-paths/README.md b/problems/out-of-boundary-paths/README.md index ed2ee896b..0fb9bf3e0 100644 --- a/problems/out-of-boundary-paths/README.md +++ b/problems/out-of-boundary-paths/README.md @@ -5,6 +5,10 @@ +[< 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)

There is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid boundary in four directions (up, down, left, right). However, you can at most move N 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 109 + 7.

@@ -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? +
+Hint 1 +WIll traversing every path is fesaible? There are many possible paths for a small matrix. Try to optimize it. +
+
+Hint 2 +Can we use some space to store the number of paths and updating them after every move? +
+
+Hint 3 +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? +
diff --git a/problems/palindrome-number/README.md b/problems/palindrome-number/README.md index b035230af..da7307e26 100644 --- a/problems/palindrome-number/README.md +++ b/problems/palindrome-number/README.md @@ -5,6 +5,10 @@ +[< 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)

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

@@ -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. +
+Hint 1 +Beware of overflow when you reverse the integer. +
diff --git a/problems/palindrome-permutation-ii/README.md b/problems/palindrome-permutation-ii/README.md index 86bfca624..bf386f3e5 100644 --- a/problems/palindrome-permutation-ii/README.md +++ b/problems/palindrome-permutation-ii/README.md @@ -5,6 +5,10 @@ +[< 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)

Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empty list if no palindromic permutation could be form.

@@ -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: Permutations II or Next Permutation. +
+Hint 1 +If a palindromic permutation exists, we just need to generate the first half of the string. +
+
+Hint 2 +To generate all distinct permutations of a (half of) string, use a similar approach from: Permutations II or Next Permutation. +
diff --git a/problems/palindrome-permutation/README.md b/problems/palindrome-permutation/README.md index 303e508a4..06d7905df 100644 --- a/problems/palindrome-permutation/README.md +++ b/problems/palindrome-permutation/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/paint-house-ii "Paint House II") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/palindrome-permutation-ii "Palindrome Permutation II") + ## 266. Palindrome Permutation (Easy)

Given a string, determine if a permutation of the string could form a palindrome.

@@ -34,6 +38,15 @@ 1. [Longest Palindrome](https://github.com/openset/leetcode/tree/master/problems/longest-palindrome) (Easy) ### Hints - 1. Consider the palindromes of odd vs even length. What difference do you notice? - 1. Count the frequency of each character. - 1. If each character occurs even number of times, then it must be a palindrome. How about character which occurs odd number of times? +
+Hint 1 +Consider the palindromes of odd vs even length. What difference do you notice? +
+
+Hint 2 +Count the frequency of each character. +
+
+Hint 3 +If each character occurs even number of times, then it must be a palindrome. How about character which occurs odd number of times? +
diff --git a/problems/partition-labels/README.md b/problems/partition-labels/README.md index ed473a9d1..770788748 100644 --- a/problems/partition-labels/README.md +++ b/problems/partition-labels/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/prime-number-of-set-bits-in-binary-representation "Prime Number of Set Bits in Binary Representation") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/largest-plus-sign "Largest Plus Sign") + ## 763. Partition Labels (Medium)

@@ -35,4 +39,7 @@ A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits 1. [Merge Intervals](https://github.com/openset/leetcode/tree/master/problems/merge-intervals) (Medium) ### Hints - 1. Try to greedily choose the smallest partition that includes the first letter. If you have something like "abaccbdeffed", then you might need to add b. You can use an map like "last['b'] = 5" to help you expand the width of your partition. +

+Hint 1 +Try to greedily choose the smallest partition that includes the first letter. If you have something like "abaccbdeffed", then you might need to add b. You can use an map like "last['b'] = 5" to help you expand the width of your partition. +
diff --git a/problems/partition-to-k-equal-sum-subsets/README.md b/problems/partition-to-k-equal-sum-subsets/README.md index a43d07ecb..63ac45a5d 100644 --- a/problems/partition-to-k-equal-sum-subsets/README.md +++ b/problems/partition-to-k-equal-sum-subsets/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/degree-of-an-array "Degree of an Array") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/falling-squares "Falling Squares") + ## 698. Partition to K Equal Sum Subsets (Medium)

Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal.

@@ -36,4 +40,7 @@ 1. [Partition Equal Subset Sum](https://github.com/openset/leetcode/tree/master/problems/partition-equal-subset-sum) (Medium) ### Hints - 1. We can figure out what target each subset must sum to. Then, let's recursively search, where at each call to our function, we choose which of k subsets the next value will join. +
+Hint 1 +We can figure out what target each subset must sum to. Then, let's recursively search, where at each call to our function, we choose which of k subsets the next value will join. +
diff --git a/problems/peeking-iterator/README.md b/problems/peeking-iterator/README.md index f7f673d9b..fb1d0d48c 100644 --- a/problems/peeking-iterator/README.md +++ b/problems/peeking-iterator/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/move-zeroes "Move Zeroes") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/inorder-successor-in-bst "Inorder Successor in BST") + ## 284. Peeking Iterator (Medium)

Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be returned by the next call to next().

@@ -31,7 +35,19 @@ Calling hasNext() after that should return peek() before next() vs next() before peek(). - 1. For a clean implementation, check out Google's guava library source code. +
+Hint 1 +Think of "looking ahead". You want to cache the next element. +
+
+Hint 2 +Is one variable sufficient? Why or why not? +
+
+Hint 3 +Test your design with call order of peek() before next() vs next() before peek(). +
+
+Hint 4 +For a clean implementation, check out Google's guava library source code. +
diff --git a/problems/set-matrix-zeroes/README.md b/problems/set-matrix-zeroes/README.md index 6fc0630c8..5f0750a23 100644 --- a/problems/set-matrix-zeroes/README.md +++ b/problems/set-matrix-zeroes/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/edit-distance "Edit Distance") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/search-a-2d-matrix "Search a 2D Matrix") + ## 73. Set Matrix Zeroes (Medium)

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.

@@ -58,9 +62,21 @@ 1. [Game of Life](https://github.com/openset/leetcode/tree/master/problems/game-of-life) (Medium) ### Hints - 1. If any cell of the matrix has a zero we can record its row and column number using additional memory. +
+Hint 1 +If any cell of the matrix has a zero we can record its row and column number using additional memory. But if you don't want to use extra memory then you can manipulate the array instead. i.e. simulating exactly what the question says. - 1. Setting cell values to zero on the fly while iterating might lead to discrepancies. What if you use some other integer value as your marker? +
+
+Hint 2 +Setting cell values to zero on the fly while iterating might lead to discrepancies. What if you use some other integer value as your marker? There is still a better approach for this problem with 0(1) space. - 1. We could have used 2 sets to keep a record of rows/columns which need to be set to zero. But for an O(1) space solution, you can use one of the rows and and one of the columns to keep track of this information. - 1. We can use the first cell of every row and column as a flag. This flag would determine whether a row or column has been set to zero. +
+
+Hint 3 +We could have used 2 sets to keep a record of rows/columns which need to be set to zero. But for an O(1) space solution, you can use one of the rows and and one of the columns to keep track of this information. +
+
+Hint 4 +We can use the first cell of every row and column as a flag. This flag would determine whether a row or column has been set to zero. +
diff --git a/problems/shortest-completing-word/README.md b/problems/shortest-completing-word/README.md index 5322d60dd..5f449f075 100644 --- a/problems/shortest-completing-word/README.md +++ b/problems/shortest-completing-word/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/largest-number-at-least-twice-of-others "Largest Number At Least Twice of Others") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/contain-virus "Contain Virus") + ## 748. Shortest Completing Word (Easy)

@@ -49,4 +53,7 @@ We return the one that occurred first. [[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] ### Hints - 1. Count only the letters (possibly converted to lowercase) of each word. If a word is shorter and the count of each letter is at least the count of that letter in the licensePlate, it is the best answer we've seen yet. +

+Hint 1 +Count only the letters (possibly converted to lowercase) of each word. If a word is shorter and the count of each letter is at least the count of that letter in the licensePlate, it is the best answer we've seen yet. +
diff --git a/problems/shuffle-an-array/README.md b/problems/shuffle-an-array/README.md index bdd1fd29f..472d54450 100644 --- a/problems/shuffle-an-array/README.md +++ b/problems/shuffle-an-array/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/ransom-note "Ransom Note") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/mini-parser "Mini Parser") + ## 384. Shuffle an Array (Medium)

Shuffle a set of numbers without duplicates. @@ -28,4 +32,7 @@ solution.shuffle();

### Hints - 1. The solution expects that we always use the original array to shuffle() else some of the test cases fail. (Credits; @snehasingh31) +
+Hint 1 +The solution expects that we always use the original array to shuffle() else some of the test cases fail. (Credits; @snehasingh31) +
diff --git a/problems/sliding-puzzle/README.md b/problems/sliding-puzzle/README.md index 1132b0b5e..998269bf6 100644 --- a/problems/sliding-puzzle/README.md +++ b/problems/sliding-puzzle/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/basic-calculator-iii "Basic Calculator III") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/minimize-max-distance-to-gas-station "Minimize Max Distance to Gas Station") + ## 773. Sliding Puzzle (Hard)

On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square represented by 0.

@@ -58,4 +62,7 @@ After move 5: [[1,2,3],[4,5,0]] [[Breadth-first Search](https://github.com/openset/leetcode/tree/master/tag/breadth-first-search/README.md)] ### Hints - 1. Perform a breadth-first-search, where the nodes are the puzzle boards and edges are if two puzzle boards can be transformed into one another with one move. +
+Hint 1 +Perform a breadth-first-search, where the nodes are the puzzle boards and edges are if two puzzle boards can be transformed into one another with one move. +
diff --git a/problems/sliding-window-maximum/README.md b/problems/sliding-window-maximum/README.md index 23daba506..aee757987 100644 --- a/problems/sliding-window-maximum/README.md +++ b/problems/sliding-window-maximum/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/product-of-array-except-self "Product of Array Except Self") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/search-a-2d-matrix-ii "Search a 2D Matrix II") + ## 239. Sliding Window Maximum (Hard)

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the max sliding window.

@@ -42,6 +46,15 @@ Could you solve it in linear time?

1. [Paint House II](https://github.com/openset/leetcode/tree/master/problems/paint-house-ii) (Hard) ### Hints - 1. How about using a data structure such as deque (double-ended queue)? - 1. The queue size need not be the same as the window’s size. - 1. Remove redundant elements and the queue should store only elements that need to be considered. +
+Hint 1 +How about using a data structure such as deque (double-ended queue)? +
+
+Hint 2 +The queue size need not be the same as the window’s size. +
+
+Hint 3 +Remove redundant elements and the queue should store only elements that need to be considered. +
diff --git a/problems/special-binary-string/README.md b/problems/special-binary-string/README.md index 5e08f533d..ccecae323 100644 --- a/problems/special-binary-string/README.md +++ b/problems/special-binary-string/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/find-anagram-mappings "Find Anagram Mappings") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/prime-number-of-set-bits-in-binary-representation "Prime Number of Set Bits in Binary Representation") + ## 761. Special Binary String (Hard)

@@ -41,9 +45,12 @@ This is the lexicographically largest string possible after some number of swaps 1. [Valid Parenthesis String](https://github.com/openset/leetcode/tree/master/problems/valid-parenthesis-string) (Medium) ### Hints - 1. Draw a line from (x, y) to (x+1, y+1) if we see a "1", else to (x+1, y-1). +

+Hint 1 +Draw a line from (x, y) to (x+1, y+1) if we see a "1", else to (x+1, y-1). A special substring is just a line that starts and ends at the same y-coordinate, and that is the lowest y-coordinate reached. Call a mountain a special substring with no special prefixes - ie. only at the beginning and end is the lowest y-coordinate reached. If F is the answer function, and S has mountain decomposition M1,M2,M3,...,Mk, then the answer is: reverse_sorted(F(M1), F(M2), ..., F(Mk)). However, you'll also need to deal with the case that S is a mountain, such as 11011000 -> 11100100. +
diff --git a/problems/sqrtx/README.md b/problems/sqrtx/README.md index a3b563fe7..f595b2a0e 100644 --- a/problems/sqrtx/README.md +++ b/problems/sqrtx/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/text-justification "Text Justification") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/climbing-stairs "Climbing Stairs") + ## 69. Sqrt(x) (Easy)

Implement int sqrt(int x).

@@ -38,5 +42,11 @@ 1. [Valid Perfect Square](https://github.com/openset/leetcode/tree/master/problems/valid-perfect-square) (Easy) ### Hints - 1. Try exploring all integers. (Credits: @annujoshi) - 1. Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) +
+Hint 1 +Try exploring all integers. (Credits: @annujoshi) +
+
+Hint 2 +Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) +
diff --git a/problems/string-compression/README.md b/problems/string-compression/README.md index 7e3819988..b6af380ab 100644 --- a/problems/string-compression/README.md +++ b/problems/string-compression/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/find-all-duplicates-in-an-array "Find All Duplicates in an Array") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/sequence-reconstruction "Sequence Reconstruction") + ## 443. String Compression (Easy)

Given an array of characters, compress it in-place.

@@ -82,4 +86,7 @@ Notice each digit has it's own entry in the array. 1. [Design Compressed String Iterator](https://github.com/openset/leetcode/tree/master/problems/design-compressed-string-iterator) (Easy) ### Hints - 1. How do you know if you are at the end of a consecutive group of characters? +
+Hint 1 +How do you know if you are at the end of a consecutive group of characters? +
diff --git a/problems/subarray-product-less-than-k/README.md b/problems/subarray-product-less-than-k/README.md index 9309b17d4..ed8570722 100644 --- a/problems/subarray-product-less-than-k/README.md +++ b/problems/subarray-product-less-than-k/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/minimum-ascii-delete-sum-for-two-strings "Minimum ASCII Delete Sum for Two Strings") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/best-time-to-buy-and-sell-stock-with-transaction-fee "Best Time to Buy and Sell Stock with Transaction Fee") + ## 713. Subarray Product Less Than K (Medium)

Your are given an array of positive integers nums.

@@ -35,4 +39,7 @@ Note that [10, 5, 2] is not included as the product of 100 is not strictly less 1. [Subarray Sum Equals K](https://github.com/openset/leetcode/tree/master/problems/subarray-sum-equals-k) (Medium) ### Hints - 1. For each j, let opt(j) be the smallest i so that nums[i] * nums[i+1] * ... * nums[j] is less than k. opt is an increasing function. +
+Hint 1 +For each j, let opt(j) be the smallest i so that nums[i] * nums[i+1] * ... * nums[j] is less than k. opt is an increasing function. +
diff --git a/problems/swap-adjacent-in-lr-string/README.md b/problems/swap-adjacent-in-lr-string/README.md index e8f20cc1e..81a84c0c5 100644 --- a/problems/swap-adjacent-in-lr-string/README.md +++ b/problems/swap-adjacent-in-lr-string/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/split-bst "Split BST") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/swim-in-rising-water "Swim in Rising Water") + ## 777. Swap Adjacent in LR String (Medium)

In a string composed of 'L', 'R', and 'X' characters, like "RXXLRXRXL", a move consists of either replacing one occurrence of "XL" with "LX", or replacing one occurrence of "RX" with "XR". Given the starting string start and the ending string end, return True if and only if there exists a sequence of moves to transform one string to the other.

@@ -34,4 +38,7 @@ XRLXXRRLX [[Brainteaser](https://github.com/openset/leetcode/tree/master/tag/brainteaser/README.md)] ### Hints - 1. Think of the L and R's as people on a horizontal line, where X is a space. The people can't cross each other, and also you can't go from XRX to RXX. +
+Hint 1 +Think of the L and R's as people on a horizontal line, where X is a space. The people can't cross each other, and also you can't go from XRX to RXX. +
diff --git a/problems/swim-in-rising-water/README.md b/problems/swim-in-rising-water/README.md index 659f422c3..b8b7bd86a 100644 --- a/problems/swim-in-rising-water/README.md +++ b/problems/swim-in-rising-water/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/swap-adjacent-in-lr-string "Swap Adjacent in LR String") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/k-th-symbol-in-grammar "K-th Symbol in Grammar") + ## 778. Swim in Rising Water (Hard)

On an N x N grid, each square grid[i][j] represents the elevation at that point (i,j).

@@ -56,4 +60,7 @@ We need to wait until time 16 so that (0, 0) and (4, 4) are connected. [[Binary Search](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)] ### Hints - 1. Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. +
+Hint 1 +Use either Dijkstra's, or binary search for the best time T for which you can reach the end if you only step on squares at most T. +
diff --git a/problems/toeplitz-matrix/README.md b/problems/toeplitz-matrix/README.md index c91ab03a5..529e1129c 100644 --- a/problems/toeplitz-matrix/README.md +++ b/problems/toeplitz-matrix/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/couples-holding-hands "Couples Holding Hands") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/reorganize-string "Reorganize String") + ## 766. Toeplitz Matrix (Easy)

A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.

@@ -65,4 +69,7 @@ The diagonal "[1, 2]" has different elements. 1. [Valid Word Square](https://github.com/openset/leetcode/tree/master/problems/valid-word-square) (Easy) ### Hints - 1. Check whether each value is equal to the value of it's top-left neighbor. +
+Hint 1 +Check whether each value is equal to the value of it's top-left neighbor. +
diff --git a/problems/unique-substrings-in-wraparound-string/README.md b/problems/unique-substrings-in-wraparound-string/README.md index 2d3a7c89b..97e1631bd 100644 --- a/problems/unique-substrings-in-wraparound-string/README.md +++ b/problems/unique-substrings-in-wraparound-string/README.md @@ -5,6 +5,10 @@ +[< Previous](https://github.com/openset/leetcode/tree/master/problems/count-the-repetitions "Count The Repetitions") +                 +[Next >](https://github.com/openset/leetcode/tree/master/problems/validate-ip-address "Validate IP Address") + ## 467. Unique Substrings in Wraparound String (Medium)

Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".

@@ -42,4 +46,7 @@ [[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] ### Hints - 1. One possible solution might be to consider allocating an array size of 26 for each character in the alphabet. (Credits to @r2ysxu) +
+Hint 1 +One possible solution might be to consider allocating an array size of 26 for each character in the alphabet. (Credits to @r2ysxu) +