TikTok User
Learn this problemProblem statement
A TikTok developer assigns integers to users in an array arr.
An arrangement is good if the absolute difference between every pair of adjacent values is at most 1. For example, [1, 2, 1] is good, but [2, 1, 3] is not because the difference between 1 and 3 is 2.
Some values are missing and are represented by arr[i] = 0. Count the ways to replace every missing value with an arbitrary integer so that the final array is good.
Because the number of ways can be large, return it modulo 10^9 + 7.
The input contains at least one known, nonzero value. A replacement value may itself be 0.
Function
tiktokUser(arr: int[]) → intExamples
Example 1
arr = [0, 0, 1]return = 9Working backward from the final value 1, the second position can be 0, 1, or 2. For each of those choices, the first position again has three valid choices. Therefore there are 3 × 3 = 9 good completions.
Constraints
1 ≤ arr.length ≤ 10^5-10^9 ≤ arr[i] ≤ 10- At least one element of
arris nonzero. 0denotes a missing value and may be replaced by any integer.
More Tiktok problems
- Can Reach the Exit with TeleportsOA · Seen Jul 2026
- Check Monotonic TriplesOA · Seen Jul 2026
- Shift Every K-th ConsonantOA · Seen Jul 2026
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Sort Matrix BordersOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Validate 3x3 Digit WindowsOA · Seen Jul 2026