Sum of squares of first N natural numbers You are given an integer 'N'. You need to find the sum of squares of the first 'N' natural numbers. For example: If 'N' = 4. You need to return 1^2 + 2^2 + 3^2 + 4^2 = 30. Input Format: The first line of input contains a single integer 'T', repr...
read more
CodingNinjas
author
2y
Step 1 : Set sum =0
Step 2 : Make a loop from i=0 to N
Step 3 : Sum = Sum + i²
Step 4 : return Sum
Anonymous
1mo
More efficient:
step 2: make loop form i=1 to N/2+1
step 3: sum = sum + i^2 + (N-i+1)^2
CodingNinjas
author
2y
Brute Force - RecursiveWrite a recursive solution for adding the sum of the squares of the first ‘N’ natural numbers.The base case would be the sum of the first natural number, which is 1.Sum up the s...
see more
CodingNinjas
author
2y
Brute Force - IterativeRun a for loop from 1 to ‘N’.Sum up the squares of each number from 1 to ‘N’.Finally, return this sum.Space Complexity: O(1)Explanation: O(1)Since we are using constant extra sp...
see more
Add answer anonymously...
Top LTIMindtree Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in LTIMindtree Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app