3522. Calculate Score After Performing Instructions
You are given two arrays,
instructionsandvalues, both of sizen.You need to simulate a process based on the following rules:
You start at the first instruction at index
i = 0with an initial score of 0.If
instructions[i]is"add":
- Add
values[i]to your score.- Move to the next instruction
(i + 1).If
instructions[i]is"jump":
- Move to the instruction at index
(i + values[i])without modifying your score.The process ends when you either:
- Go out of bounds (i.e.,
i < 0 or i >= n), or- Attempt to revisit an instruction that has been previously executed. The revisited instruction is not executed.
Return your score at the end of the process.
1 | class Solution { |