Generating Login Codes
Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Snowflake's "Generating Login Codes" showed up in candidate reports in September 2026, and the setup looks stranger than it is. Two arrays, one operation: merge any subsegment into its sum. You want the longest the two arrays can be once they match. Example 1 turns [2,4,3,7,10] and [6,5,5,10] into [6,10,10] and returns 3. Underneath it's a prefix-sum matching problem wearing a security-software costume. If you've seen the equal-sum partition idea, you've seen this. If the OA is tomorrow, read the trick below, and keep StealthCoder running as a backup if your mind goes blank mid-assessment.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Merging subsegments means each final element is a contiguous block sum. Two final arrays are equal only if their block boundaries land on the same prefix sums. So the answer is the count of shared prefix sums between the two arrays, including the total. Use two pointers: walk both arrays, keep running sums a and b, advance whichever is smaller, and when they're equal, increment the count and move both on. If the total sums differ, return -1 right away. Check that first. In the example, prefix sums of [2,4,3,7,10] are 2,6,9,16,26 and of [6,5,5,10] are 6,11,16,26. Shared: 6, 16, 26, so 3. The common pitfall is trying to simulate merges or run DP, which is overkill. Another is forgetting that all elements are assumed positive, which is what makes greedy matching valid. It's O(n+m) time and O(1) space. If you freeze on the reduction during the live OA, StealthCoder is the hedge that surfaces this approach.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Generating Login Codes cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Snowflake's OA.
Snowflake reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Generating Login Codes FAQ
What's the trick in Generating Login Codes?+
Every final element is a contiguous block sum, so equal arrays must share cut points at the same prefix sums. Count the prefix sums common to both arrays, including the total. If the totals differ, return -1. No merge simulation needed.
How hard is this Snowflake OA question really?+
Easy to medium once you see the reduction. The statement is wordy, which makes it feel harder than it is. The code is a short two-pointer loop. Most of the difficulty is recognizing that merging means choosing shared prefix sums.
When do I return -1?+
Return -1 when the total sums of the two arrays differ. Since merging only preserves the total, matching arrays must have equal sums. If totals match, the full-array merge guarantees at least length 1, so the answer is never below 1.
Should I use a hash set or two pointers?+
Both work. A hash set of one array's prefix sums, then counting matches in the other, is simple. Two pointers uses constant extra space and is just as short. Either is O(n+m). Pick whichever you can write without bugs under pressure.
How do I prepare for this in 48 hours?+
Write the two-pointer prefix-sum match from scratch twice. Test it on the Example 1 values, a case with differing totals, and a case where only the total matches. Also review similar problems on equal-sum splits and subarray sums so the pattern is fast to spot.