Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether Digits Are Strictly Decreasing

Basic Acceptance 87.15% Points 10.00

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 = 10¹8
Companies
TCS American Express
Topics
Data Structures Basics String Searching Algorithms
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions