1622. Fancy Sequence
https://leetcode.com/problems/fancy-sequence
Description
Write an API that generates fancy sequences using the append
, addAll
, and multAll
operations.
Implement the Fancy
class:
Fancy()
Initializes the object with an empty sequence.void append(val)
Appends an integerval
to the end of the sequence.void addAll(inc)
Increments all existing values in the sequence by an integerinc
.void multAll(m)
Multiplies all existing values in the sequence by an integerm
.int getIndex(idx)
Gets the current value at indexidx
(0-indexed) of the sequence modulo109 + 7
. If the index is greater or equal than the length of the sequence, return-1
.
Example 1:
Constraints:
1 <= val, inc, m <= 100
0 <= idx <= 105
At most
105
calls total will be made toappend
,addAll
,multAll
, andgetIndex
.
ac
Last updated