Loading...
Loading...
You are given two lists of strings callers and receivers of the same length. Each index i records one phone call: the person named callers[i] called the person named receivers[i].
A call chain is a sequence of people where each person called the next person in the sequence. Its length is the number of people in it. For example, if A called B, B called C, and C called D, then A, B, C, D is a call chain of length 4.
Return the length of the longest call chain.
A person can make and receive any number of calls, and the same call can be recorded more than once. Nobody calls themselves. You can assume no call chain ever leads back to a person who is already in it.
Input: callers = ["A","B","C","E","F"], receivers = ["B","C","D","F","G"]
Output: 4
Explanation: A called B, B called C, and C called D, so A, B, C, D is a call chain of 4 people.
The other chain, E, F, G, has only 3 people.
Input: callers = ["X","Z","Y"], receivers = ["Y","Y","W"]
Output: 3
Explanation: X and Z both called Y, and Y called W. So X, Y, W and Z, Y, W are call chains of 3 people.
X and Z never appear in the same chain, because a chain only moves from a caller to the person they called.
Input: callers = ["P","P","Q","R","P"], receivers = ["S","Q","R","S","Q"]
Output: 4
Explanation: P called S directly, but P also called Q, Q called R, and R called S. So P, Q, R, S is a call chain of 4 people.
The call from P to Q is recorded twice. It still adds only one step to a chain.
callers.length ≤104receivers.length = callers.lengthcallers[i].length, receivers[i].length ≤10callers[i] and receivers[i] consist of uppercase English letterscallers[i] = receivers[i]