Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Longest Increasing Sequence of Digits

Basic Acceptance 76.65% Points 10

You are given a non-negative integer n. Your task is to return the length of the longest strictly increasing run of consecutive digits when read from left to right.

A run is strictly increasing if each digit is greater than the digit immediately before it. If no adjacent digits satisfy this condition, the longest increasing run has a length of 1.

Examples
Example 1

Input: n = 1235123
Output: 4
Explanation: The sequence 1, 2, 3, 5 forms the longest strictly increasing run, with a length of 4.

Example 2

Input: n = 54321
Output: 1
Explanation: The digits are strictly decreasing, so no increasing run extends beyond a single digit.

Example 3

Input: n = 1234
Output: 4
Explanation: The entire sequence 1, 2, 3, 4 is strictly increasing, giving a length of 4.

Constraints
  • 0 <= n <= 1018
Topics
Data Structures Basics
Companies
Accenture eBay
Added 31 Oct 2026 76.65% acceptance
Ln 1, Col 1Sign in to save your code
1234
4