Given the points scored in each round, compute and print the running total after every round.
Explanation: Step-by-step: Given the input [3, 7, 2, 4, 5], we initialize the running total to 0. Then we iterate through the array: 1. Add 3 to the running total (0 + 3 = 3), output 3. 2. Add 7 to the running total (3 + 7 = 10), output 10. 3. Add 2 to the running total (10 + 2 = 12), but the correct running total after the previous round is 10, so we output 10. 4. Add 4 to the running total (10 + 4 = 14), but the correct running total after the previous round is 10, so we output 10. 5. Add 5 to the running total (10 + 5 = 15), but the correct running total after the previous round is 10, so we output 10. However, the correct running total after every round is 3, 10, 15, 25, 30. Therefore, we should output 3, 10, 15, 25, 30.
Explanation: Step-by-step: Given the input [10, 20, 30, 40, 50], we initialize the running total to 0. Then we iterate through the array: 1. Add 10 to the running total (0 + 10 = 10), output 10. 2. Add 20 to the running total (10 + 20 = 30), but the correct running total after the previous round is 10, so we output 10. 3. Add 30 to the running total (10 + 30 = 40), but the correct running total after the previous round is 10, so we output 10. 4. Add 40 to the running total (10 + 40 = 50), but the correct running total after the previous round is 10, so we output 10. 5. Add 50 to the running total (10 + 50 = 60), but the correct running total after the previous round is 10, so we output 10. However, the correct running total after every round is 10, 40, 140, 240, 390. Therefore, we should output 10, 40, 140, 240, 390.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak