#3522
Calculate Score After Performing Instructions
specialist · 780 · lc medium +31 · 56.9% accepted · 46 likes · top 52%
Description
Simulate execution over arrays instructions and values (both length n), starting at index 0 with score 0.
- "add": add values[i] to score, advance to i + 1.
- "jump": move to index i + values[i] without changing score.
Stop when the index goes out of bounds or an already-visited instruction would be executed (without executing it).
Return the final score.
Code
1
2
3