Longest Stable Transaction Period
Learn this problemProblem statement
See the Image Source section at the very bottom of the page for the original problem statement 🐻❄️🐻
In a bustling financial world, you are the guardian of stability, keeping a close eye on daily transactions. Each day’s net transaction value is recorded in an array, and your mission is to uncover the longest period of calm in this sea of numbers. But there’s a catch — a period is only considered stable if the sum of transactions over consecutive days can be evenly divided by a special number, the stability factor, k. Your goal is to write a function that searches through these records, finds the longest stretch of days where this condition holds true, and returns the length of that stable period.
Function
duolingoLongestTransaction(transactions: int[], k: int) → intExamples
Example 1
transactions = [2, 3, 1, 4, 1, 5, 9]k = 3return = 4
The longest stable period can be formed by the subarray [3, 1, 4, 1], where the sum 3 + 1 + 4 + 1 = 9 is divisible by 3.
Example 2
transactions = [3]k = 2return = 0
The array has only one element which is not divisible by 2, hence there are no stable periods and the result is 0.
Constraints
🍓🍓