Decode length with cap

Write codeMedium20 min

Your task

A run-length-encoded string repeats blocks of the form <count><char>, where <count> is a positive decimal integer of one or more digits and <char> is a single lowercase letter (e.g. "3a2b1c" decodes to "aaabbc", length 6). Given the encoded string s and an integer cap, return the decoded length, but as soon as the running decoded length would exceed cap, stop and return -1. The empty string decodes to length 0. Counts can be large, so you must not materialize the decoded string.

Examples

run_length_decode_capacity(s: str, cap: int) -> int
Example 1
Inputrun_length_decode_capacity("3a2b1c", 100)
Output6