Longest Stable Transaction Period
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.
1Example 1
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.
2Example 2
The array has only one element which is not divisible by 2, hence there are no stable periods and the result is 0.
Constraints
Limits and guarantees your solution can rely on.
ππ