Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest
continuous increasing subsequence.
Input: [1, 3, 5, 4, 7] Output: 3 Explanation: The longest continuous increasing subsequence is [1, 3, 5], its length is 3. Even though [1, 3, 5, 7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4.
Input: [2, 2, 2, 2, 2] Output: 1 Explanation: The longest continuous increasing subsequence is , its length is 1.
Note: Length of the array will not exceed 10,000.
Implement Magic Dictionary
Implement a magic directory with
For the method
buildDict, you’ll be given a list of non-repetitive words to build a dictionary.
For the method
search, you’ll be given a word, and judge whether if you modify exactly one character into another character in this word, the modified word is in the dictionary you just built.
Input: buildDict(["hello", "leetcode"]), Output: Null Input: search("hello"), Output: False Input: search("hhllo"), Output: True Input: search("hell"), Output: False Input: search("leetcoded"), Output: False
- You may assume that all the inputs are consist of lowercase letters
- For contest purpose, the test data is rather small by now. You could think about highly efficient algorithm after the contest.
- Please remember to RESET your class variables declared in class MagicDictionary, as static/class variables are persisted across multiple test cases. Please see here for more details.
Cut Off Trees for Golf Event
You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-negative 2D map, in this map:
obstaclecan’t be reached.
groundcan be walked through.
The place with number bigger than 1represents a
treecan be walked through, and this positive number represents the tree’s height.
You are asked to cut off all the trees in this forest in the order of tree’s height - always cut off the tree with lowest height first. And after cutting, the original place has the tree will become a grass (value 1).
You will start from the point (0, 0) and you should output the minimum steps you need to walk to cut off all the trees. If you can’t cut off all the trees, output -1 in that situation.
You are guaranteed that no two
trees have the same height and there is at least one tree needs to be cut off.
Input: [ [1, 2, 3], [0, 0, 4], [7, 6, 5] ] Output: 6
Input: [ [1, 2, 3], [0, 0, 0], [7, 6, 5] ] Output: -1
Input: [ [2, 3, 4], [0, 0, 5], [8, 7, 6] ] Output: 6 Explanation: You started from the point (0, 0) and you can cut off the tree in (0, 0) directly without walking.
Hint: size of the given matrix will not exceed 50x50.
Number of Longest Increasing Subsequence
Given an unsorted array of integers, find the number of longest increasing subsequence.
Input: [1, 3, 5, 4, 7] Output: 2 Explanation: The two longest increasing subsequence are [1, 3, 4, 7] and [1, 3, 5, 7].
Input: [2, 2, 2, 2, 2] Output: 5 Explanation: The length of longest continuous increasing subsequence is 1, and there are 5 subsequences' length is 1, so output 5.
Note: Length of the given array will be not exceed 2000 and the answer is guaranteed to be fit in 32-bit signed int.