You are given a list of transactions. Each transaction has a merchant name, an amount, and a timestamp in seconds. The transactions come as three parallel lists, in any order: merchants[i], amounts[i] and timestamps[i] describe transaction i.
Group the transactions by merchant and find the merchant with the highest total transaction volume within any 24-hour sliding window. A 24-hour window is any contiguous period of exactly 86400 seconds. A window that starts at window_start includes every transaction with timestamp t such that window_start <= t < window_start + 86400.
For each merchant, consider every possible 24-hour window and take the largest volume among them. Return the name of the merchant whose best window has the highest volume. If several merchants tie, return the lexicographically smallest name.
Function Signature
def highest_volume_merchant(merchants: list[str], amounts: list[int], timestamps: list[int]) -> str:
Rules
-
The three lists have the same length, and index
i
across them is one transaction.
-
The window is half-open. Two transactions of the same merchant can share a window only when their timestamps differ by less than
86400
; a gap of exactly
86400
puts them in different windows.
-
A merchant's volume in a window is the sum of the amounts of its transactions inside that window. Several transactions may share a timestamp, and all of them count.
-
Ties between merchants are broken by ordinary string comparison: return the smallest name.
Constraints
-
1 <= n <= 10^5
, where
n
is the number of transactions
-
1 <= amounts[i] <= 10^6
-
0 <= timestamps[i] <= 10^9
-
Each merchant name has 1 to 20 lowercase English letters.
Examples
Input: merchants = ["alice","bob","alice","bob","alice"], amounts = [100,200,300,150,250], timestamps = [1000,2000,5000,50000,10000]
Output: "alice"
Alice's transactions at 1000, 5000 and 10000 fit in one window, for a volume of 100 + 300 + 250 = 650. Bob's two transactions are 48000 seconds apart, so one window holds both, for 200 + 150 = 350, and Alice wins with 650.
Input: merchants = ["shop","shop","store","store"], amounts = [500,500,1000,1], timestamps = [0,86399,0,86400]
Output: "shop"
For "shop", timestamps 0 and 86399 differ by less than 86400, so the window starting at 0 holds both, for 1000. For "store", timestamps 0 and 86400 differ by exactly 86400, so no window holds both and its best window is the single 1000; the merchants tie at 1000 and "shop" is the smaller name.
Input: merchants = ["zed","zed","zed","amy"], amounts = [40,30,50,70], timestamps = [90000,0,80000,10]
Output: "zed"
In time order, zed has 30 at 0, 50 at 80000 and 40 at 90000. The first and last are 90000 seconds apart, so no window holds all three, and the best window (starting at 80000) holds 50 + 40 = 90, which beats amy's 70.