Tap here to switch tabs
Problem
Submissions

Problem: Calculate Score After Performing Instructions

Try to solve the Calculate Score After Performing Instructions problem.

Statement

You are given two arrays of length n: a string array instructions and an integer array values.

A simulation begins at index 00 with an initial score of 00. At each step at index i:

  • If index i has already been visited or is out of bounds (meaning i <0< 0 or i ≥\geq n), the process ends immediately.

  • If instructions[i] is equal to "add", add values[i] to the score and advance to index i +1+ 1.

  • If instructions[i] is equal to "jump", move directly to index i ++ values[i].

Return the total score accumulated when the process terminates.

Constraints:

  • n == instructions.length == values.length

  • 1≤1 \leq n ≤105\leq 10^5

  • instructions[i] is either "add" or "jump".

  • −105≤-10^5 \leq values[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Calculate Score After Performing Instructions

Try to solve the Calculate Score After Performing Instructions problem.

Statement

You are given two arrays of length n: a string array instructions and an integer array values.

A simulation begins at index 00 with an initial score of 00. At each step at index i:

  • If index i has already been visited or is out of bounds (meaning i <0< 0 or i ≥\geq n), the process ends immediately.

  • If instructions[i] is equal to "add", add values[i] to the score and advance to index i +1+ 1.

  • If instructions[i] is equal to "jump", move directly to index i ++ values[i].

Return the total score accumulated when the process terminates.

Constraints:

  • n == instructions.length == values.length

  • 1≤1 \leq n ≤105\leq 10^5

  • instructions[i] is either "add" or "jump".

  • −105≤-10^5 \leq values[i] ≤105\leq 10^5