Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Find the Longest Increasing Sequence of Digits

Basic Acceptance 76.65% Points 10.00

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 = 10¹8
Companies
Accenture eBay
Topics
Data Structures Basics
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