Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
longest-increasing-subsequence-ii.json36 linesDownload Raw Back to root
1{2  "id": 2526,3  "name": "longest-increasing-subsequence-ii",4  "difficulty": "Hard",5  "link": "https://leetcode.com/problems/longest-increasing-subsequence-ii/",6  "date": "2022-09-04",7  "task_description": "You are given an integer array `nums` and an integer `k`. Find the longest subsequence of `nums` that meets the following requirements: The subsequence is **strictly increasing** and The difference between adjacent elements in the subsequence is **at most** `k`. Return_ the length of the **longest** **subsequence** that meets the requirements._ A **subsequence** is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements. **Example 1:** ``` **Input:** nums = [4,2,1,4,3,4,5,8,15], k = 3 **Output:** 5 **Explanation:** The longest subsequence that meets the requirements is [1,3,4,5,8]. The subsequence has a length of 5, so we return 5. Note that the subsequence [1,3,4,5,8,15] does not meet the requirements because 15 - 8 = 7 is larger than 3. ``` **Example 2:** ``` **Input:** nums = [7,4,5,1,8,12,4,7], k = 5 **Output:** 4 **Explanation:** The longest subsequence that meets the requirements is [4,5,8,12]. The subsequence has a length of 4, so we return 4. ``` **Example 3:** ``` **Input:** nums = [1,5], k = 1 **Output:** 1 **Explanation:** The longest subsequence that meets the requirements is [1]. The subsequence has a length of 1, so we return 1. ``` **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i], k <= 105`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums = [4,2,1,4,3,4,5,8,15], k = 3",12      "output": "5 "13    },14    {15      "label": "Example 2",16      "input": "nums = [7,4,5,1,8,12,4,7], k = 5",17      "output": "4 "18    },19    {20      "label": "Example 3",21      "input": "nums = [1,5], k = 1",22      "output": "1 "23    }24  ],25  "constraints": [26    "The subsequence is strictly increasing and",27    "The difference between adjacent elements in the subsequence is at most k.",28    "1 <= nums.length <= 105",29    "1 <= nums[i], k <= 105"30  ],31  "python_template": "class Solution(object):\n    def lengthOfLIS(self, nums, k):\n        \"\"\"\n        :type nums: List[int]\n        :type k: int\n        :rtype: int\n        \"\"\"\n        ",32  "java_template": "class Solution {\n    public int lengthOfLIS(int[] nums, int k) {\n        \n    }\n}",33  "metadata": {34    "func_name": "lengthOfLIS"35  }36}