Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether a Number Is a Kaprekar Number

Basic Acceptance 88% Points 10

You are given a positive integer n. Your task is to determine whether it is a Kaprekar number.

A number is a Kaprekar number if its square can be split into two parts such that the sum of the left and right parts equals the original number. The right part must be non-zero, and the split must preserve the digit positions of the squared number.

Return Yes if n satisfies this property; otherwise, return No.

Examples
Example 1

Input: n = 45
Output: Yes
Explanation: The square of 45 is 2025. Splitting it into 20 and 25 gives 20 + 25 = 45.

Example 2

Input: n = 9
Output: Yes
Explanation: The square of 9 is 81. Splitting it into 8 and 1 gives 8 + 1 = 9.

Example 3

Input: n = 10
Output: No
Explanation: The square of 10 is 100. No valid split produces two parts whose sum equals 10.

Constraints
  • 1 <= n <= 105
Topics
Data Structures Basics
Companies
Apple Morgan Stanly
Added 31 Oct 2026 88% acceptance
Ln 1, Col 1Sign in to save your code
1
Yes