Problem · Array
Find Fair Indexes
Learn this problemProblem statement
You are given two arrays A and B consisting of N integers each.
Index K is named fair if the four sums A[0]+...A[K-1]), A[K]+...+A[N-1]), B[0]+...+B[K-1]) and B[K]+...+B[N-1]) are all equal. In other words, K is the index where the two arrays, A and B, can be split (into two non-empty arrays each) in such a way that the sums of the resulting arrays' elements are equal.
For example, given arrays A = [4,-1, 0, 3] and B = [-2, 5, 0, 3], index K = 2 is fair. The sums of the subarrays are all equal: 4+(-1) = 3; 0+3 = 3; -2 + 5 = 3 and 0 + 3 = 3.
Function
findFairIndex(A: int[], B: int[]) → intExamples
Example 1
A = [4,-1,0,3]B = [-2,5,0,3]return = 2Index K = 2 is fair. The sums of the subarrays are all equal: 4+(-1) = 3; 0+3 = 3; -2 + 5 = 3 and 0 + 3 = 3.
Example 2
A = [2,-2,-3,3]B = [0,0,4,-4]return = 1Index K = 1 is fair. The sums of the subarrays are all equal: 2 = 2; -2+(-3)+3 = 0; 0 = 0; 0+4+(-4) = 0.
Example 3
A = [4,-1,0,3]B = [-2,6,0,4]return = 0There is no fair index K in this case.
Example 4
A = [1,4,2,-2,5]B = [7,-2,-2,2,5]return = 2Index K = 2 is fair. The sums of the subarrays are all equal: 1+4 = 5; 2+(-2)+5 = 5; 7+(-2) = 5; (-2)+2+5 = 5.
Constraints
🥑🥑More Microsoft problems
- Authentication SystemOA · Seen Jul 2026
- Binary String Swap TimeOA · Seen Jul 2026
- Minimum Effort Task ScheduleOA · Seen Jul 2026
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026