Skip to content

Practice Calculate Score After Performing Instructions

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3522
LeetCode Problem

Calculate Score After Performing Instructions

Problem Statement

Begin at instruction index 0 with score zero. For add, add values[i] to the score and advance to i + 1. For jump, move to i + values[i] without changing the score. Stop upon leaving the array or before executing an instruction a second time. Return the final score.

Source: Calculate Score After Performing Instructions on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
instructions = ["jump","add","add","jump","add","jump"], values = [2,1,3,1,-2,-3]
Output
1

# Example 2

Input
instructions = ["jump","add","add"], values = [3,1,1]
Output
0

# Example 3

Input
instructions = ["jump"], values = [0]
Output
0

Constraints

n == instructions.length == values.length
1 <= n <= 10^5
instructions[i] is either "add" or "jump".
-10^5 <= values[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Calculate Score After Performing Instructions.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.