Dsa
Dynamic Programming
Medium
Sequence Reinforcement
You're building a reinforcement learning model that requires processing sequences of actions. Each action has a score associated with it, and you want to maximize the total score by selecting a subsequence from the list of actions. However, you can only select an action if there are no other actions with a score greater than or equal to its score in the selected subsequence. Write a program to find the maximum total score of the selected subsequence.
Input format:
- The first line contains an integer n (number of actions).
- The second line contains n space-separated integers (scores of each action).
Output format:
- A single integer representing the maximum total score of the selected subsequence.
Example:
Input:
5
10 5 4 9 6
Output:
25
Key concepts
dynamic_programmingsequence
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now