Ctrl K

Three in a Row

Medium
You are given an integer total. Find three consecutive integers (they may be negative) that add up to total, and return them in increasing order. If no such integers exist, return an empty list.
Example 1
total=21 → [6, 7, 8]

6 + 7 + 8 = 21.

Example 2
total=10 → []

The sum of three consecutive integers is always a multiple of 3, and 10 is not.

Example 3
total=0 → [-1, 0, 1]

The integers may be negative: −1 + 0 + 1 = 0.

Constraints
  • 0 ≤ total ≤ 10¹⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMultiplying Digit Strings MediumMultiply Complex Numbers in Strings MediumTotal of a Fraction Chain MediumSolve for x MediumRotating Operator Countdown Medium
loading Python…
Input
total=21
Expected
[6, 7, 8]

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