Mid/SeniorMathSimulation

Find Three Consecutive Integers That Sum to a Given Number

Given an integer num, return three consecutive integers as a sorted array that sum to num.

If num cannot be expressed as the sum of three consecutive integers, return an empty array.

Example 1
Inputnum = 33
Output[10,11,12]
33 can be expressed as 10 + 11 + 12, and these are three consecutive integers.
Example 2
Inputnum = 4
Output[]
There is no way to express 4 as the sum of 3 consecutive integers.

Constraints

  • 0 <= num <= 10^15

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate