Explanation

549.Count the Operations in a Summing Loop

Easy
For the loop that adds the numbers 1 to n, return [sum, comparisons, additions, increments]: the sum it computes, how many times the condition i <= n is checked, how many additions into the sum happen, and how many times i is increased. Complexity analysis starts by counting basic operationsBasic OperationA single simple step such as one comparison, one addition or one assignment, assumed to take constant time. — comparisons, additions, assignments — instead of timing a program with a stopwatch. Counting is independent of how fast a particular computer is, so it describes the algorithm itself.

Example 1:

Input: n = 3

Output: [6,4,3,3]

Example 2:

Input: n = 0

Output: [0,1,0,0]

+ 4 hidden test cases run on Submit.

Constraints:

  • ●0 ≤ n ≤ 10000

n =

3