TikTok User
Updated
Problem 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 interview questions
- Center of the Largest Perfect X-ShapeOA · Seen Nov 2026
- Count Subarrays Matching a Comparison PatternOA · Seen Nov 2026
- Count Suffix Word PairsOA · Seen Nov 2026
- Minimum Cost of Every K-Capable Model SetOA · Seen Nov 2026
- Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Oct 2026
- Next Greater Indices and Maximum GapPHONE SCREEN · Seen Oct 2026
- Count Subarrays with at Least K Equal-Fruit PairsOA · Seen Oct 2026
- Shell Command Counts with History ReferencesOA · Seen Oct 2026
- Product Minus Sum of DigitsOA · Seen Aug 2026
- Count 2x2 Submatrices by Black CellsOA · Seen Aug 2026
Similar questions at other companies
- Maximum Signal Walk in a Server TreeTower Research Capital · OA
- Count Nondecreasing Digit-Sum ArraysMicrosoft · OAMicrosoft interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Profitable Currency Exchange CycleOptiver · OAOptiver interview questions
- Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
- Match an XOR-Adjusted SumSquarepoint Capital · OASquarepoint Capital interview questions
- Count Numbers with a Prime Digit SumRippling · OARippling interview questions
- Count Permutations Without Three Equal Parities in a RowGoogle · OAGoogle interview questions
- String Transformation (Also for Infra Automation Intern)Snowflake · OASnowflake interview questions
- Digit SumBank of New York Mellon · OA
TikTok interview experiences
- TikTok AI Infra Intern LLM Round 2: 1 Experience
- TikTok AI Infra Intern DeepSpeed Round: 1 Experience
- TikTok AI Infra Intern Kernel Round: 1 Experience
- TikTok AI Infra Intern Interviews, 3 Rounds: 1 Experience
- TikTok AI Infra Intern Interview Timeline: 1 Experience
- TikTok AI Infra Intern Onsite Round 2: 1 Experience