Generating Login Codes
Frequency: Reported
An employee's login process uses two arrays: initialLogin of size n and standardLogin of size m.
The security software may repeatedly perform this operation on either array:
- Select any contiguous subsegment and replace it with the sum of its elements.
For example, [1, 5, 6, 8, 2] can become [12, 8, 2] by replacing [1, 5, 6] with 12.
Perform any number of operations on both arrays. Maximize the length of the equal arrays that can result. That maximum length is the login code. If the arrays cannot be made equal, return -1.
Example
text
n = 5
initialLogin = [2, 4, 3, 7, 10]
m = 4
standardLogin = [6, 5, 5, 10]One optimal sequence is:
- Replace
[3, 7]with10ininitialLogin, producing[2, 4, 10, 10]. - Replace
[5, 5]with10instandardLogin, producing[6, 10, 10]. - Replace
[2, 4]with6ininitialLogin, producing[6, 10, 10].
Return 3.
Function
text
getLoginCodes(initialLogin[n], standardLogin[m]) -> intConstraints
text
1 <= n, m <= 2 * 10^5
1 <= initialLogin[i], standardLogin[i] <= 10^9