Construct Distinct Integers Summing to Zero
Updated
Problem statement
Given an integer N, return an array containing exactly N distinct integers whose sum is zero.
You may return any array satisfying these conditions, in any order. There is no required pattern or particular range of values beyond the signed 32-bit integer return type.
Function
solution(N: int) → int[]Examples
Example 1
N = 4return = [1,0,-3,2]The four values are distinct and sum to zero. Another valid answer is [-2,1,-4,5]. The array [1,-1,1,3] is invalid: it repeats 1 and does not satisfy the conditions.
Example 2
N = 3return = [-1,0,1]These three distinct values sum to zero. Other valid arrays are also accepted.
Example 3
N = 1return = [0]This boundary example has only one element, which must be zero.
Constraints
1 <= N <= 100.- For this exercise, return values are signed 32-bit integers.
More Marshall Wace Online Assessment questions
- Count Letters with Ordered Lowercase and Uppercase OccurrencesOA · Seen Oct 2025
- Maximum Trailing Zeros on a Path with at Most One TurnOA · Seen Oct 2025
- Shortest Subarray Covering an Integer RangeOA · Seen Oct 2025
- Maximum Events in a 60-Second WindowOA · Seen Aug 2025
- Successful Logins from Multiple CountriesOA · Seen Aug 2025
- Maximize Remaining Item Types After Clearing Consecutive ShelvesOA · Seen Nov 2024
- Shortest String After Erasing Equal PairsOA · Seen Nov 2024
- Count Distinct Tags in a Fixed-Radius Circle (Practice Reconstruction)OA · Seen Apr 2024
- Generate Unique Company Email AddressesOA · Seen Apr 2024
- Reconstruct a Two-Row Binary MatrixOA · Seen Apr 2024
Similar questions at other companies
- Count Valid Square PairsAuxoAI · OA
- Picked Player Who LostSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Server InvestmentRippling · OARippling interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions
- Unique Integers That Sum to ZeroNVIDIA · OANVIDIA interview questions
- Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
- Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
- Maximum Student-Teacher DistanceChubb · OAChubb interview questions
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions