← Questions

Distinct integers that match a count of positive pair sums

0
CognitionCodingLast asked Oct 2024

A coding interview question asked in Cognition's online assessment, last asked Oct 2024. It tests math, greedy and constructive.

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 add up to 0 (an element paired with itself included, so no element is 0), and for every i, p[i] equals the number of indices j…

Sign in to unlock this question

The full prompt, the worked answer and your own canvas or code with the AI tutor. New accounts get 5 credits: each one unlocks a question for good.

Where it's asked

What it tests

math · greedy · constructive

Your code and the AI tutor open when you unlock this question.