bowang0911/leetcode huggingface dataset:
Cycle Length Queries in a Tree

You are given an integer `n`. There is a **complete binary tree** with `2n - 1` nodes. The root of that tree is the node with the value `1`, and every node with a value `val` in the range `[1, 2n - 1 - 1]` has two children where:

*   The left node has the value `2 * val`, and
*   The right node has the value `2 * val + 1`.

You are also given a 2D integer array `queries` of length `m`, where `queries[i] = [ai, bi]`. For each query, solve the following problem:

1.  Add an edge between the nodes with values `ai` and `bi`.
2.  Find the length of the cycle in the graph.
3.  Remove the added edge between nodes with values `ai` and `bi`.

**Note** that:

*   A **cycle** is a path that starts and ends at the same node, and each edge in the path is visited only once.
*   The length of a cycle is the number of edges visited in the cycle.
*   There could be multiple edges between two nodes in the tree after adding the edge of the query.

Return _an array_ `answer` _of length_ `m` _where_ `answer[i]` _is the answer to the_ `ith` _query._

**Example 1:**

**Input:** n = 3, queries = \[\[5,3\],\[4,7\],\[2,3\]\]
**Output:** \[4,5,3\]
**Explanation:** The diagrams above show the tree of 23 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.
- After adding the edge between nodes 3 and 5, the graph contains a cycle of nodes \[5,2,1,3\]. Thus answer to the first query is 4. We delete the added edge and process the next query.
- After adding the edge between nodes 4 and 7, the graph contains a cycle of nodes \[4,2,1,3,7\]. Thus answer to the second query is 5. We delete the added edge and process the next query.
- After adding the edge between nodes 2 and 3, the graph contains a cycle of nodes \[2,1,3\]. Thus answer to the third query is 3. We delete the added edge.

**Example 2:**

**Input:** n = 2, queries = \[\[1,2\]\]
**Output:** \[2\]
**Explanation:** The diagram above shows the tree of 22 - 1 nodes. Nodes colored in red describe the nodes in the cycle after adding the edge.
- After adding the edge between nodes 1 and 2, the graph contains a cycle of nodes \[2,1\]. Thus answer for the first query is 2. We delete the added edge.

**Constraints:**

*   `2 <= n <= 30`
*   `m == queries.length`
*   `1 <= m <= 105`
*   `queries[i].length == 2`
*   `1 <= ai, bi <= 2n - 1`
*   `ai != bi`
Check if There is a Path With Equal Number of 0's And 1's

You are given a **0-indexed** `m x n` **binary** matrix `grid`. You can move from a cell `(row, col)` to any of the cells `(row + 1, col)` or `(row, col + 1)`.

Return `true` _if there is a path from_ `(0, 0)` _to_ `(m - 1, n - 1)` _that visits an **equal** number of_ `0`_'s and_ `1`_'s_. Otherwise return `false`.

**Example 1:**

**Input:** grid = \[\[0,1,0,0\],\[0,1,0,0\],\[1,0,1,0\]\]
**Output:** true
**Explanation:** The path colored in blue in the above diagram is a valid path because we have 3 cells with a value of 1 and 3 with a value of 0. Since there is a valid path, we return true.

**Example 2:**

**Input:** grid = \[\[1,1,0\],\[0,0,1\],\[1,0,0\]\]
**Output:** false
**Explanation:** There is no path in this grid with an equal number of 0's and 1's.

**Constraints:**

*   `m == grid.length`
*   `n == grid[i].length`
*   `2 <= m, n <= 100`
*   `grid[i][j]` is either `0` or `1`.
Maximum Enemy Forts That Can Be Captured

You are given a **0-indexed** integer array `forts` of length `n` representing the positions of several forts. `forts[i]` can be `-1`, `0`, or `1` where:

*   `-1` represents there is **no fort** at the `ith` position.
*   `0` indicates there is an **enemy** fort at the `ith` position.
*   `1` indicates the fort at the `ith` the position is under your command.

Now you have decided to move your army from one of your forts at position `i` to an empty position `j` such that:

*   `0 <= i, j <= n - 1`
*   The army travels over enemy forts **only**. Formally, for all `k` where `min(i,j) < k < max(i,j)`, `forts[k] == 0.`

While moving the army, all the enemy forts that come in the way are **captured**.

Return _the **maximum** number of enemy forts that can be captured_. In case it is **impossible** to move your army, or you do not have any fort under your command, return `0`_._

**Example 1:**

**Input:** forts = \[1,0,0,-1,0,0,0,0,1\]
**Output:** 4
**Explanation:**
- Moving the army from position 0 to position 3 captures 2 enemy forts, at 1 and 2.
- Moving the army from position 8 to position 3 captures 4 enemy forts.
Since 4 is the maximum number of enemy forts that can be captured, we return 4.

**Example 2:**

**Input:** forts = \[0,0,1,-1\]
**Output:** 0
**Explanation:** Since no enemy fort can be captured, 0 is returned.

**Constraints:**

*   `1 <= forts.length <= 1000`
*   `-1 <= forts[i] <= 1`
Reward Top K Students

You are given two string arrays `positive_feedback` and `negative_feedback`, containing the words denoting positive and negative feedback, respectively. Note that **no** word is both positive and negative.

Initially every student has `0` points. Each positive word in a feedback report **increases** the points of a student by `3`, whereas each negative word **decreases** the points by `1`.

You are given `n` feedback reports, represented by a **0-indexed** string array `report` and a **0-indexed** integer array `student_id`, where `student_id[i]` represents the ID of the student who has received the feedback report `report[i]`. The ID of each student is **unique**.

Given an integer `k`, return _the top_ `k` _students after ranking them in **non-increasing** order by their points_. In case more than one student has the same points, the one with the lower ID ranks higher.

**Example 1:**

**Input:** positive\_feedback = \[ "smart ", "brilliant ", "studious "\], negative\_feedback = \[ "not "\], report = \[ "this student is studious ", "the student is smart "\], student\_id = \[1,2\], k = 2
**Output:** \[1,2\]
**Explanation:** 
Both the students have 1 positive feedback and 3 points but since student 1 has a lower ID he ranks higher.

**Example 2:**

**Input:** positive\_feedback = \[ "smart ", "brilliant ", "studious "\], negative\_feedback = \[ "not "\], report = \[ "this student is not studious ", "the student is smart "\], student\_id = \[1,2\], k = 2
**Output:** \[2,1\]
**Explanation:** 
- The student with ID 1 has 1 positive feedback and 1 negative feedback, so he has 3-1=2 points. 
- The student with ID 2 has 1 positive feedback, so he has 3 points. 
Since student 2 has more points, \[2,1\] is returned.

**Constraints:**

*   `1 <= positive_feedback.length, negative_feedback.length <= 104`
*   `1 <= positive_feedback[i].length, negative_feedback[j].length <= 100`
*   Both `positive_feedback[i]` and `negative_feedback[j]` consists of lowercase English letters.
*   No word is present in both `positive_feedback` and `negative_feedback`.
*   `n == report.length == student_id.length`
*   `1 <= n <= 104`
*   `report[i]` consists of lowercase English letters and spaces `' '`.
*   There is a single space between consecutive words of `report[i]`.
*   `1 <= report[i].length <= 100`
*   `1 <= student_id[i] <= 109`
*   All the values of `student_id[i]` are **unique**.
*   `1 <= k <= n`
Minimize the Maximum of Two Arrays

We have two arrays `arr1` and `arr2` which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions:

*   `arr1` contains `uniqueCnt1` **distinct** positive integers, each of which is **not divisible** by `divisor1`.
*   `arr2` contains `uniqueCnt2` **distinct** positive integers, each of which is **not divisible** by `divisor2`.
*   **No** integer is present in both `arr1` and `arr2`.

Given `divisor1`, `divisor2`, `uniqueCnt1`, and `uniqueCnt2`, return _the **minimum possible maximum** integer that can be present in either array_.

**Example 1:**

**Input:** divisor1 = 2, divisor2 = 7, uniqueCnt1 = 1, uniqueCnt2 = 3
**Output:** 4
**Explanation:** 
We can distribute the first 4 natural numbers into arr1 and arr2.
arr1 = \[1\] and arr2 = \[2,3,4\].
We can see that both arrays satisfy all the conditions.
Since the maximum value is 4, we return it.

**Example 2:**

**Input:** divisor1 = 3, divisor2 = 5, uniqueCnt1 = 2, uniqueCnt2 = 1
**Output:** 3
**Explanation:** 
Here arr1 = \[1,2\], and arr2 = \[3\] satisfy all conditions.
Since the maximum value is 3, we return it.

**Example 3:**

**Input:** divisor1 = 2, divisor2 = 4, uniqueCnt1 = 8, uniqueCnt2 = 2
**Output:** 15
**Explanation:** 
Here, the final possible arrays can be arr1 = \[1,3,5,7,9,11,13,15\], and arr2 = \[2,6\].
It can be shown that it is not possible to obtain a lower maximum satisfying all conditions. 

**Constraints:**

*   `2 <= divisor1, divisor2 <= 105`
*   `1 <= uniqueCnt1, uniqueCnt2 < 109`
*   `2 <= uniqueCnt1 + uniqueCnt2 <= 109`
Shortest Distance to Target String in a Circular Array

You are given a **0-indexed** **circular** string array `words` and a string `target`. A **circular array** means that the array's end connects to the array's beginning.

*   Formally, the next element of `words[i]` is `words[(i + 1) % n]` and the previous element of `words[i]` is `words[(i - 1 + n) % n]`, where `n` is the length of `words`.

Starting from `startIndex`, you can move to either the next word or the previous word with `1` step at a time.

Return _the **shortest** distance needed to reach the string_ `target`. If the string `target` does not exist in `words`, return `-1`.

**Example 1:**

**Input:** words = \[ "hello ", "i ", "am ", "leetcode ", "hello "\], target =  "hello ", startIndex = 1
**Output:** 1
**Explanation:** We start from index 1 and can reach  "hello " by
- moving 3 units to the right to reach index 4.
- moving 2 units to the left to reach index 4.
- moving 4 units to the right to reach index 0.
- moving 1 unit to the left to reach index 0.
The shortest distance to reach  "hello " is 1.

**Example 2:**

**Input:** words = \[ "a ", "b ", "leetcode "\], target =  "leetcode ", startIndex = 0
**Output:** 1
**Explanation:** We start from index 0 and can reach  "leetcode " by
- moving 2 units to the right to reach index 3.
- moving 1 unit to the left to reach index 3.
The shortest distance to reach  "leetcode " is 1.

**Example 3:**

**Input:** words = \[ "i ", "eat ", "leetcode "\], target =  "ate ", startIndex = 0
**Output:** -1
**Explanation:** Since  "ate " does not exist in `words`, we return -1.

**Constraints:**

*   `1 <= words.length <= 100`
*   `1 <= words[i].length <= 100`
*   `words[i]` and `target` consist of only lowercase English letters.
*   `0 <= startIndex < words.length`
Take K of Each Character From Left and Right

You are given a string `s` consisting of the characters `'a'`, `'b'`, and `'c'` and a non-negative integer `k`. Each minute, you may take either the **leftmost** character of `s`, or the **rightmost** character of `s`.

Return _the **minimum** number of minutes needed for you to take **at least**_ `k` _of each character, or return_ `-1` _if it is not possible to take_ `k` _of each character._

**Example 1:**

**Input:** s =  "aabaaaacaabc ", k = 2
**Output:** 8
**Explanation:** 
Take three characters from the left of s. You now have two 'a' characters, and one 'b' character.
Take five characters from the right of s. You now have four 'a' characters, two 'b' characters, and two 'c' characters.
A total of 3 + 5 = 8 minutes is needed.
It can be proven that 8 is the minimum number of minutes needed.

**Example 2:**

**Input:** s =  "a ", k = 1
**Output:** -1
**Explanation:** It is not possible to take one 'b' or 'c' so return -1.

**Constraints:**

*   `1 <= s.length <= 105`
*   `s` consists of only the letters `'a'`, `'b'`, and `'c'`.
*   `0 <= k <= s.length`
Maximum Tastiness of Candy Basket

You are given an array of positive integers `price` where `price[i]` denotes the price of the `ith` candy and a positive integer `k`.

The store sells baskets of `k` **distinct** candies. The **tastiness** of a candy basket is the smallest absolute difference of the **prices** of any two candies in the basket.

Return _the **maximum** tastiness of a candy basket._

**Example 1:**

**Input:** price = \[13,5,1,8,21,2\], k = 3
**Output:** 8
**Explanation:** Choose the candies with the prices \[13,5,21\].
The tastiness of the candy basket is: min(|13 - 5|, |13 - 21|, |5 - 21|) = min(8, 8, 16) = 8.
It can be proven that 8 is the maximum tastiness that can be achieved.

**Example 2:**

**Input:** price = \[1,3,1\], k = 2
**Output:** 2
**Explanation:** Choose the candies with the prices \[1,3\].
The tastiness of the candy basket is: min(|1 - 3|) = min(2) = 2.
It can be proven that 2 is the maximum tastiness that can be achieved.

**Example 3:**

**Input:** price = \[7,7,7,7\], k = 2
**Output:** 0
**Explanation:** Choosing any two distinct candies from the candies we have will result in a tastiness of 0.

**Constraints:**

*   `2 <= k <= price.length <= 105`
*   `1 <= price[i] <= 109`
Number of Great Partitions

You are given an array `nums` consisting of **positive** integers and an integer `k`.

**Partition** the array into two ordered **groups** such that each element is in exactly **one** group. A partition is called great if the **sum** of elements of each group is greater than or equal to `k`.

Return _the number of **distinct** great partitions_. Since the answer may be too large, return it **modulo** `109 + 7`.

Two partitions are considered distinct if some element `nums[i]` is in different groups in the two partitions.

**Example 1:**

**Input:** nums = \[1,2,3,4\], k = 4
**Output:** 6
**Explanation:** The great partitions are: (\[1,2,3\], \[4\]), (\[1,3\], \[2,4\]), (\[1,4\], \[2,3\]), (\[2,3\], \[1,4\]), (\[2,4\], \[1,3\]) and (\[4\], \[1,2,3\]).

**Example 2:**

**Input:** nums = \[3,3,3\], k = 4
**Output:** 0
**Explanation:** There are no great partitions for this array.

**Example 3:**

**Input:** nums = \[6,6\], k = 2
**Output:** 2
**Explanation:** We can either put nums\[0\] in the first partition or in the second partition.
The great partitions will be (\[6\], \[6\]) and (\[6\], \[6\]).

**Constraints:**

*   `1 <= nums.length, k <= 1000`
*   `1 <= nums[i] <= 109`
Count the Number of K-Big Indices

You are given a **0-indexed** integer array `nums` and a positive integer `k`.

We call an index `i` **k-big** if the following conditions are satisfied:

*   There exist at least `k` different indices `idx1` such that `idx1 < i` and `nums[idx1] < nums[i]`.
*   There exist at least `k` different indices `idx2` such that `idx2 > i` and `nums[idx2] < nums[i]`.

Return _the number of k-big indices_.

**Example 1:**

**Input:** nums = \[2,3,6,5,2,3\], k = 2
**Output:** 2
**Explanation:** There are only two 2-big indices in nums:
- i = 2 --> There are two valid idx1: 0 and 1. There are three valid idx2: 2, 3, and 4.
- i = 3 --> There are two valid idx1: 0 and 1. There are two valid idx2: 3 and 4.

**Example 2:**

**Input:** nums = \[1,1,1\], k = 3
**Output:** 0
**Explanation:** There are no 3-big indices in nums.

**Constraints:**

*   `1 <= nums.length <= 105`
*   `1 <= nums[i], k <= nums.length`
Count the Digits That Divide a Number

Given an integer `num`, return _the number of digits in `num` that divide_ `num`.

An integer `val` divides `nums` if `nums % val == 0`.

**Example 1:**

**Input:** num = 7
**Output:** 1
**Explanation:** 7 divides itself, hence the answer is 1.

**Example 2:**

**Input:** num = 121
**Output:** 2
**Explanation:** 121 is divisible by 1, but not 2. Since 1 occurs twice as a digit, we return 2.

**Example 3:**

**Input:** num = 1248
**Output:** 4
**Explanation:** 1248 is divisible by all of its digits, hence the answer is 4.

**Constraints:**

*   `1 <= num <= 109`
*   `num` does not contain `0` as one of its digits.
Distinct Prime Factors of Product of Array

Given an array of positive integers `nums`, return _the number of **distinct prime factors** in the product of the elements of_ `nums`.

**Note** that:

*   A number greater than `1` is called **prime** if it is divisible by only `1` and itself.
*   An integer `val1` is a factor of another integer `val2` if `val2 / val1` is an integer.

**Example 1:**

**Input:** nums = \[2,4,3,7,10,6\]
**Output:** 4
**Explanation:**
The product of all the elements in nums is: 2 \* 4 \* 3 \* 7 \* 10 \* 6 = 10080 = 25 \* 32 \* 5 \* 7.
There are 4 distinct prime factors so we return 4.

**Example 2:**

**Input:** nums = \[2,4,8,16\]
**Output:** 1
**Explanation:**
The product of all the elements in nums is: 2 \* 4 \* 8 \* 16 = 1024 = 210.
There is 1 distinct prime factor so we return 1.

**Constraints:**

*   `1 <= nums.length <= 104`
*   `2 <= nums[i] <= 1000`
Partition String Into Substrings With Values at Most K

You are given a string `s` consisting of digits from `1` to `9` and an integer `k`.

A partition of a string `s` is called **good** if:

*   Each digit of `s` is part of **exactly** one substring.
*   The value of each substring is less than or equal to `k`.

Return _the **minimum** number of substrings in a **good** partition of_ `s`. If no **good** partition of `s` exists, return `-1`.

**Note** that:

*   The **value** of a string is its result when interpreted as an integer. For example, the value of `"123 "` is `123` and the value of `"1 "` is `1`.
*   A **substring** is a contiguous sequence of characters within a string.

**Example 1:**

**Input:** s =  "165462 ", k = 60
**Output:** 4
**Explanation:** We can partition the string into substrings  "16 ",  "54 ",  "6 ", and  "2 ". Each substring has a value less than or equal to k = 60.
It can be shown that we cannot partition the string into less than 4 substrings.

**Example 2:**

**Input:** s =  "238182 ", k = 5
**Output:** -1
**Explanation:** There is no good partition for this string.

**Constraints:**

*   `1 <= s.length <= 105`
*   `s[i]` is a digit from `'1'` to `'9'`.
*   `1 <= k <= 109`

.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; } .spoiler {overflow:hidden;} .spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;} .spoilerbutton\[value="Show Message"\] + .spoiler > div {margin-top:-500%;} .spoilerbutton\[value="Hide Message"\] + .spoiler {padding:5px;}
Closest Prime Numbers in Range

Given two positive integers `left` and `right`, find the two integers `num1` and `num2` such that:

*   `left <= nums1 < nums2 <= right` .
*   `nums1` and `nums2` are both **prime** numbers.
*   `nums2 - nums1` is the **minimum** amongst all other pairs satisfying the above conditions.

Return _the positive integer array_ `ans = [nums1, nums2]`. _If there are multiple pairs satisfying these conditions, return the one with the minimum_ `nums1` _value or_ `[-1, -1]` _if such numbers do not exist._

A number greater than `1` is called **prime** if it is only divisible by `1` and itself.

**Example 1:**

**Input:** left = 10, right = 19
**Output:** \[11,13\]
**Explanation:** The prime numbers between 10 and 19 are 11, 13, 17, and 19.
The closest gap between any pair is 2, which can be achieved by \[11,13\] or \[17,19\].
Since 11 is smaller than 17, we return the first pair.

**Example 2:**

**Input:** left = 4, right = 6
**Output:** \[-1,-1\]
**Explanation:** There exists only one prime number in the given range, so the conditions cannot be satisfied.

**Constraints:**

*   `1 <= left <= right <= 106`

.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0;  } .spoiler {overflow:hidden;} .spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;} .spoilerbutton\[value="Show Message"\] + .spoiler > div {margin-top:-500%;} .spoilerbutton\[value="Hide Message"\] + .spoiler {padding:5px;}
Maximum Frequency Score of a Subarray

You are given an integer array `nums` and a **positive** integer `k`.

The **frequency score** of an array is the sum of the **distinct** values in the array raised to the power of their **frequencies**, taking the sum **modulo** `109 + 7`.

*   For example, the frequency score of the array `[5,4,5,7,4,4]` is `(43 + 52 + 71) modulo (109 + 7) = 96`.

Return _the **maximum** frequency score of a **subarray** of size_ `k` _in_ `nums`. You should maximize the value under the modulo and not the actual value.

A **subarray** is a contiguous part of an array.

**Example 1:**

**Input:** nums = \[1,1,1,2,1,2\], k = 3
**Output:** 5
**Explanation:** The subarray \[2,1,2\] has a frequency score equal to 5. It can be shown that it is the maximum frequency score we can have.

**Example 2:**

**Input:** nums = \[1,1,1,1,1,1\], k = 4
**Output:** 1
**Explanation:** All the subarrays of length 4 have a frequency score equal to 1.

**Constraints:**

*   `1 <= k <= nums.length <= 105`
*   `1 <= nums[i] <= 106`
Categorize Box According to Criteria

Given four integers `length`, `width`, `height`, and `mass`, representing the dimensions and mass of a box, respectively, return _a string representing the **category** of the box_.

*   The box is `"Bulky "` if:
    *   **Any** of the dimensions of the box is greater or equal to `104`.
    *   Or, the **volume** of the box is greater or equal to `109`.
*   If the mass of the box is greater or equal to `100`, it is `"Heavy ".`
*   If the box is both `"Bulky "` and `"Heavy "`, then its category is `"Both "`.
*   If the box is neither `"Bulky "` nor `"Heavy "`, then its category is `"Neither "`.
*   If the box is `"Bulky "` but not `"Heavy "`, then its category is `"Bulky "`.
*   If the box is `"Heavy "` but not `"Bulky "`, then its category is `"Heavy "`.

**Note** that the volume of the box is the product of its length, width and height.

**Example 1:**

**Input:** length = 1000, width = 35, height = 700, mass = 300
**Output:**  "Heavy "
**Explanation:** 
None of the dimensions of the box is greater or equal to 104. 
Its volume = 24500000 <= 109. So it cannot be categorized as  "Bulky ".
However mass >= 100, so the box is  "Heavy ".
Since the box is not  "Bulky " but  "Heavy ", we return  "Heavy ".

**Example 2:**

**Input:** length = 200, width = 50, height = 800, mass = 50
**Output:**  "Neither "
**Explanation:** 
None of the dimensions of the box is greater or equal to 104.
Its volume = 8 \* 106 <= 109. So it cannot be categorized as  "Bulky ".
Its mass is also less than 100, so it cannot be categorized as  "Heavy " either. 
Since its neither of the two above categories, we return  "Neither ".

**Constraints:**

*   `1 <= length, width, height <= 105`
*   `1 <= mass <= 103`
Find Consecutive Integers from a Data Stream

For a stream of integers, implement a data structure that checks if the last `k` integers parsed in the stream are **equal** to `value`.

Implement the **DataStream** class:

*   `DataStream(int value, int k)` Initializes the object with an empty integer stream and the two integers `value` and `k`.
*   `boolean consec(int num)` Adds `num` to the stream of integers. Returns `true` if the last `k` integers are equal to `value`, and `false` otherwise. If there are less than `k` integers, the condition does not hold true, so returns `false`.

**Example 1:**

**Input**
\[ "DataStream ",  "consec ",  "consec ",  "consec ",  "consec "\]
\[\[4, 3\], \[4\], \[4\], \[4\], \[3\]\]
**Output**
\[null, false, false, true, false\]

**Explanation**
DataStream dataStream = new DataStream(4, 3); //value = 4, k = 3 
dataStream.consec(4); // Only 1 integer is parsed, so returns False. 
dataStream.consec(4); // Only 2 integers are parsed.
                      // Since 2 is less than k, returns False. 
dataStream.consec(4); // The 3 integers parsed are all equal to value, so returns True. 
dataStream.consec(3); // The last k integers parsed in the stream are \[4,4,3\].
                      // Since 3 is not equal to value, it returns False.

**Constraints:**

*   `1 <= value, num <= 109`
*   `1 <= k <= 105`
*   At most `105` calls will be made to `consec`.