Conversation Token Trim
Messages are [text,tokens]. Keep the newest suffix whose total tokens fit the budget, preserving chronological order.
Examples
EXAMPLE WALKTHROUGHnewest suffix
A guided view of the published example, not a trace of your code.
INPUT
[[["a",3],["b",4],["c",2]],6]TASKtrim_messages()
EXPECTED OUTPUT
[["b",4],["c",2]]Start with the input values shown in this example.
Example 1 of 2
Input: messages = [["a",3],["b",4],["c",2]], budget = 6
Output: [["b",4],["c",2]]
Explanation: newest suffix
Input: messages = [["a",7]], budget = 3
Output: []
Explanation: none fit
Hint 1
Walk backward, then reverse the selected messages.