Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether Digits Are Strictly Decreasing

Basic Acceptance 87.15% Points 10

You are given a non-negative integer n. Your task is to determine whether its digits, read from left to right, are strictly decreasing.

Each digit must be smaller than the digit immediately before it. If any digit is equal to or greater than the previous digit, return No. Otherwise, return Yes.

Examples
Example 1

Input: n = 9521
Output: Yes
Explanation: Each digit is smaller than the digit before it: 9 > 5 > 2 > 1.

Example 2

Input: n = 9524
Output: No
Explanation: The final digit, 4, is greater than the preceding digit, 2, so the digits are not strictly decreasing.

Example 3

Input: n = 7
Output: Yes
Explanation: A single-digit number satisfies the condition because there are no adjacent digits to compare.

Constraints
  • 0 <= n <= 1018
Topics
Data Structures Basics String Searching Algorithms
Companies
TCS American Express
Added 31 Oct 2026 87.15% acceptance
Ln 1, Col 1Sign in to save your code
2 4 8
yes