← Questions

Distinct integers that match a count of positive pair sums

0
CognitionCodingLast asked Oct 2024

You are given n non-negative counts p[0..n-1]. Build n distinct integers a[0..n-1] such that no two of them (an element with itself included) add up to 0, and for every i, p[i] equals the number of indices j (j = i counts) with a[i] + a[j] > 0.

Among all valid answers, return one whose largest absolute value is as small as possible; return None when no such sequence exists. n can be up to 100,000.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding