Webhook retry deadline

Write codeEasy14 minStripe style

Your task

A delivery queue retries a webhook until the receiver accepts it. attempt_results[i] is "ok" or "fail" for the i-th attempt, and attempt_seconds[i] is how long that attempt runs before its verdict arrives. The first attempt starts at second 0. After a failure the queue waits before trying again: first_backoff seconds after the first failure, then twice the previous wait each time, never longer than max_backoff. The queue abandons the delivery when an attempt would start later than give_up_after seconds. An attempt already running is never cut short, so a success can land after that deadline. Return the second at which the accepting attempt returns, or -1 when the queue abandons the delivery or runs out of listed attempts. The two lists have the same length, every duration is at least 0, and first_backoff is at most max_backoff.

Examples

webhook_retry_finish(attempt_results: list[str], attempt_seconds: list[int], first_backoff: int, max_backoff: int, give_up_after: int) -> int
Example 1
Inputwebhook_retry_finish(["fail", "fail", "ok"], [2, 2, 3], 5, 30, 100)
Output22
Example 2
Inputwebhook_retry_finish(["fail", "fail"], [1, 1], 2, 8, 100)
Output-1
Example 3
Inputwebhook_retry_finish(["fail", "ok"], [1, 100], 4, 10, 5)
Output105