Ctrl K

Smallest Set Dodging a Sum

Medium
You are given two integers count and banned. Build a set of count distinct positive integers in which no two different elements add up to banned. Return the smallest possible sum of such a set.
Example 1
count=4, banned=6 → 12

Take 1, 2 and 3 (the 3 has no partner, since it appears only once); 4 and 5 would pair with 2 and 1 to make 6, so the fourth number is 6. The total is 1 + 2 + 3 + 6 = 12.

Example 2
count=3, banned=1 → 6

Two distinct positive integers never add up to 1, so 1, 2, 3 work.

Constraints
  • 1 ≤ count ≤ 50
  • 1 ≤ banned ≤ 50
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSmallest Number From Digit Factors MediumOne Digit Swap MediumLargest Number With Non-Decreasing Digits MediumFewest Guests by Lanyard Color MediumUp or Down for Every Post Medium
loading Python…
Input
count=4, banned=6
Expected
12

Run checks the first 3 tests in your browser. Submit checks all 77 tests on the server, hidden ones included.