Given a non-negative integer n, return the sum of squares of all integers from 1 to n. The sum is calculated as 11 + 22 + 33 + ... + nn. Return 0 if n is 0 or null.

Examples:

Input: n = 1 Output: 1 Explanation: 1*1 = 1 Input: n = 3 Output: 14 Explanation: 1*1 + 2*2 + 3*3 = 1 + 4 + 9 = 14 Input: n = 5 Output: 55 Explanation: 1*1 + 2*2 + 3*3 + 4*4 + 5*5 = 1 + 4 + 9 + 16 + 25 = 55 Input: n = 0 Output: 0 Explanation: No numbers to square, return 0 Input: n = null Output: 0 Explanation: Null input returns 0
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 All Time Leaderboard

Contest runs January 1, 1970 - December 31, 9999. Complete challenges to climb the leaderboard!

Points are calculated for challenges completed during the contest period.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In