Given a non-negative integer n, return true if n is a perfect square. A perfect square is an integer that is the product of some non-negative integer multiplied by itself. For example, 16 is a perfect square because 4 * 4 = 16. Return false for negative numbers.

Examples:

Input: n = 16 Output: true Explanation: 4 * 4 = 16 Input: n = 25 Output: true Explanation: 5 * 5 = 25 Input: n = 14 Output: false Explanation: No integer squared equals 14 Input: n = 0 Output: true Explanation: 0 * 0 = 0 Input: n = 100 Output: true Explanation: 10 * 10 = 100
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

🏆 #CodeEveryDay August 2026

Contest runs August 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In