Please enter your email address or userHandle.
Given the value of n, we need to find the sum of the series where i-th term is sum of first i odd natural numbers.
NOTE: Sum of the series 1 + (1+3) + (1+3+5) + (1+3+5+7) + …… + (1+3+5+7+…+(2n-1))
Input: n = 2
Explanation: 1 + (1+3) = 5
Hence sum of the series is 5.
Input: n = 5
Explanation: 1 + (1+3) + (1+3+5) +
(1+3+5+7) + (1+3+5+7+9) = 55.
Hence sum of the series is 55.
You dont need to read input or print anything. Complete the function sumOfTheSeries() which takes n as input parameter and returns the sum of the series of n terms.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
1<= n <=1000
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.