FastPrepGenerating Login Codes
Problems/Generating Login Codes

Generating Login Codes

Snowflake logoSnowflake● MediumNEW GRADINTERNOA
QuestionFunctionExamples

Problem statement

Special thanks: 🌷 A special thank you to our lovely, amazing frenz who shared that this question appeared again on July 11, 2026! ദ്ദി(˵ •̀ ᴗ - ˵ ) ✧ 🩵

In a software company, each employee's login process involves two arrays: initialLogin of size n and standardLogin of size m.

The security software transforms these arrays by repeatedly performing an operation:

  • Select any subsegment of either array and replace it with the sum of its elements.

For example, the array [1, 5, 6, 8, 2] can be transformed into [12, 8, 2] by replacing the subsegment [1, 5, 6] with [12].

The goal is to maximize the length of equal arrays after performing the operations any number of times on both initialLogin and standardLogin. The login code is the maximum possible length of these equal arrays. If the arrays cannot be made equal through the operations, the initialLogin is considered invalid, and the result should be -1.

Determine the login code based on the provided initialLogin and standardLogin, or return -1 if initialLogin is invalid.

Function

getLoginCodes(initialLogin: int[], standardLogin: int[]) → int

Complete the function getLoginCodes in the editor with the following parameters:

  • initialLogin[n]: the initial array
  • standardLogin[m]: the standard array used by the security software

Returns int: the login code

Examples

Example 1

initialLogin = [2, 4, 3, 7, 10]standardLogin = [6, 5, 5, 10]return = 3

n = 5, initialLogin = [2, 4, 3, 7, 10], m = 4, and standardLogin = [6, 5, 5, 10].

An optimal sequence is:

Operation NumberOperationinitialLogin After OperationstandardLogin After Operation
1Replace the subsegment [3, 7] with [10] in initialLogin.[2, 4, 10, 10][6, 5, 5, 10]
2Replace the subsegment [5, 5] with [10] in standardLogin.[2, 4, 10, 10][6, 10, 10]
3Replace the subsegment [2, 4] with [6] in initialLogin.[6, 10, 10][6, 10, 10]

Return the maximum possible length, 3.

More Snowflake problems

  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public int getLoginCodes(int[] initialLogin, int[] standardLogin) {
      // write your code here
    }
}
Checking account…