Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
count-the-hidden-sequences.json43 linesDownload Raw Back to root
1{2  "id": 2249,3  "name": "count-the-hidden-sequences",4  "difficulty": "Medium",5  "link": "https://leetcode.com/problems/count-the-hidden-sequences/",6  "date": "2022-01-08",7  "task_description": "You are given a **0-indexed** array of `n` integers `differences`, which describes the **differences **between each pair of **consecutive **integers of a **hidden** sequence of length `(n + 1)`. More formally, call the hidden sequence `hidden`, then we have that `differences[i] = hidden[i + 1] - hidden[i]`. You are further given two integers `lower` and `upper` that describe the **inclusive** range of values `[lower, upper]` that the hidden sequence can contain. For example, given `differences = [1, -3, 4]`, `lower = 1`, `upper = 6`, the hidden sequence is a sequence of length `4` whose elements are in between `1` and `6` (**inclusive**). `[3, 4, 1, 5]` and `[4, 5, 2, 6]` are possible hidden sequences. `[5, 6, 3, 7]` is not possible since it contains an element greater than `6`. `[1, 2, 3, 4]` is not possible since the differences are not correct. Return _the number of **possible** hidden sequences there are._ If there are no possible sequences, return `0`. **Example 1:** ``` **Input:** differences = [1,-3,4], lower = 1, upper = 6 **Output:** 2 **Explanation:** The possible hidden sequences are: - [3, 4, 1, 5] - [4, 5, 2, 6] Thus, we return 2. ``` **Example 2:** ``` **Input:** differences = [3,-4,5,1,-2], lower = -4, upper = 5 **Output:** 4 **Explanation:** The possible hidden sequences are: - [-3, 0, -4, 1, 2, 0] - [-2, 1, -3, 2, 3, 1] - [-1, 2, -2, 3, 4, 2] - [0, 3, -1, 4, 5, 3] Thus, we return 4. ``` **Example 3:** ``` **Input:** differences = [4,-7,2], lower = 3, upper = 6 **Output:** 0 **Explanation:** There are no possible hidden sequences. Thus, we return 0. ``` **Constraints:** `n == differences.length` `1 <= n <= 105` `-105 <= differences[i] <= 105` `-105 <= lower <= upper <= 105`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "differences = [1,-3,4], lower = 1, upper = 6",12      "output": "2 "13    },14    {15      "label": "Example 2",16      "input": "differences = [3,-4,5,1,-2], lower = -4, upper = 5",17      "output": "4 "18    },19    {20      "label": "Example 3",21      "input": "differences = [4,-7,2], lower = 3, upper = 6",22      "output": "0 "23    }24  ],25  "constraints": [26    "For example, given differences = [1, -3, 4], lower = 1, upper = 6, the hidden sequence is a sequence of length 4 whose elements are in between 1 and 6 (inclusive).\n\n\t\n[3, 4, 1, 5] and [4, 5, 2, 6] are possible hidden sequences.\n[5, 6, 3, 7] is not possible since it contains an element greater than 6.\n[1, 2, 3, 4] is not possible since the differences are not correct.",27    "[3, 4, 1, 5] and [4, 5, 2, 6] are possible hidden sequences.",28    "[5, 6, 3, 7] is not possible since it contains an element greater than 6.",29    "[1, 2, 3, 4] is not possible since the differences are not correct.",30    "[3, 4, 1, 5] and [4, 5, 2, 6] are possible hidden sequences.",31    "[5, 6, 3, 7] is not possible since it contains an element greater than 6.",32    "[1, 2, 3, 4] is not possible since the differences are not correct.",33    "n == differences.length",34    "1 <= n <= 105",35    "-105 <= differences[i] <= 105",36    "-105 <= lower <= upper <= 105"37  ],38  "python_template": "class Solution(object):\n    def numberOfArrays(self, differences, lower, upper):\n        \"\"\"\n        :type differences: List[int]\n        :type lower: int\n        :type upper: int\n        :rtype: int\n        \"\"\"\n        ",39  "java_template": "class Solution {\n    public int numberOfArrays(int[] differences, int lower, int upper) {\n        \n    }\n}",40  "metadata": {41    "func_name": "numberOfArrays"42  }43}