Good Ways to Split an Array
Updated
Problem statement
You are given an array of non-negative integers nums. Split it into three non-empty contiguous subarrays A1, A2, and A3.
Let S1, S2, and S3 be their sums. Count the number of splits such that S2 <= S1 + S3. Return the answer modulo 10^9 + 7.
Function
countGoodSplits(nums: int[]) → intExamples
Example 1
nums = [1,2,3,4]return = 3The valid split points are after [1] | [2] | [3,4], [1] | [2,3] | [4], and [1,2] | [3] | [4]. All three satisfy S2 <= S1 + S3.
More Salesforce Phone Screen questions
- Detect a Cycle in a Linked ListPHONE SCREEN · Seen Oct 2026
- Find Rows Common to Two TablesPHONE SCREEN · Seen Oct 2026
- Merge Two Sorted Linked ListsPHONE SCREEN · Seen Oct 2026
- Minimum Window of Required WordsPHONE SCREEN · Seen Aug 2026
- Permutations of Unique CharactersPHONE SCREEN · Seen Aug 2026
- Minimum Window SubstringPHONE SCREEN · Seen Aug 2026
- Optimal Account BalancingPHONE SCREEN · Seen Jul 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
Similar questions at other companies
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Two Non-Overlapping Increasing BlocksAdobe · PHONE SCREENAdobe interview questions
- Random Pick with Weight Using Recorded DrawsMeta · PHONE SCREENMeta interview questions
- Longest Run of Ones After Flipping k ZerosC3.ai · PHONE SCREENC3.ai interview questions
- Count Recorded Events in Time IntervalsSnowflake · PHONE SCREENSnowflake interview questions
- Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
- Totals from a Tiered Rate TableMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Choose ContainersIMC Trading · OAIMC Trading interview questions
- Random Pick with Weight Using Recorded DrawsAmazon · ONSITE INTERVIEW
- TikTok Metrics AnalysisTikTok · OATikTok interview questions