Practice Fancy Sequence
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Fancy starts empty. append(val) adds an element; addAll(inc) increases every existing element; multAll(m) multiplies every existing element. getIndex(idx) returns the current zero-based value modulo 10^9+7, or -1 if the index is beyond the sequence. Earlier bulk operations do not affect later appends. Practice approach: Represent bulk changes as one affine transform. Store each appended value after undoing the current transform using modular inversion. The allowed multipliers are nonzero modulo the prime, so this inverse exists. Use exact modular multiplication; floating-point integers can lose precision. Queries apply the current transform to the normalized value.
Source: Fancy Sequence on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["Fancy","append","addAll","append","multAll","getIndex","getIndex","getIndex"] [[],[4],[3],[2],[5],[0],[1],[2]]
[null,null,null,null,null,35,10,-1]
The first value becomes (4+3)*5=35. The later appended 2 only receives multiplication, producing 10.
Constraints
Related LeetCode Problems
Practice more problems similar to Fancy Sequence.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.