You are given four lists of the same length: customers, providers, items, and days. Each index i describes one record: customer customers[i] received item items[i] from provider providers[i] on day days[i]. The records are sorted by day, so days is non-decreasing.
A customer and an item form a qualifying pair when two records exist such that:
both records have that customer and that item,
the two records have different providers, and
the two days differ by at most 30.
Return every qualifying pair once, as a single string made of the customer, one space, and the item, for example "P1 Atorvastatin". Return the qualifying pairs in any order. If no pair qualifies, return an empty list.
Examples
Example 1
Input: customers = ["P1","P1","P2","P2"], providers = ["D1","D2","D3","D4"], items = ["Atorvastatin","Atorvastatin","Metformin","Metformin"], days = [10,36,60,84]
Output: ["P1 Atorvastatin","P2 Metformin"]
Explanation: Customer P1 received Atorvastatin from D1 on day 10 and from D2 on day 36. The
providers differ and the days differ by 26, so "P1 Atorvastatin" qualifies. Customer P2
received Metformin from D3 on day 60 and from D4 on day 84, which differ by 24, so
"P2 Metformin" qualifies too.
Example 2
Input: customers = ["A","A","A"], providers = ["X","X","X"], items = ["pen","pen","pen"], days = [1,2,3]
Output: []
Explanation: All three records come from provider X. No two records have different
providers, so nothing qualifies.
Example 3
Input: customers = ["A","B","A","B"], providers = ["X","X","Y","Y"], items = ["pen","pen","pen","pen"], days = [0,0,30,31]
Output: ["A pen"]
Explanation: Customer A received pen from X on day 0 and from Y on day 30. The days differ by
exactly 30, which is within the window, so "A pen" qualifies. Customer B received pen from X
on day 0 and from Y on day 31. The days differ by 31, so "B pen" does not qualify.
Constraints
customers, providers, items, and days all have the same length n
1≤n≤105
Every customer, provider, and item is a string of 1 to 20 characters, each a letter or a digit.
0≤days[i]≤109
days[i]≤days[i + 1] for every valid i
The window is fixed at 30 days.
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run