Webhook retry deadline
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.
webhook_retry_finish(attempt_results: list[str], attempt_seconds: list[int], first_backoff: int, max_backoff: int, give_up_after: int) → int[["fail","fail","ok"],[2,2,3],5,30,100]out22[["fail","fail"],[1,1],2,8,100]out-1[["fail","ok"],[1,100],4,10,5]out105State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[["fail","fail","ok"],[2,2,3],5,30,100]22not run yetsample[["fail","fail"],[1,1],2,8,100]-1not run yetsample[["fail","ok"],[1,100],4,10,5]105not run yetsample