Skip to content
Decoder

Splitting a String Into Descending Consecutive Values

Medium

Problem

Given a string of digits s, decide whether it can be split into two or more non-empty pieces whose numeric values are **in descending order and each exactly one less** than the piece before. Pieces may have leading zeros ("0090" is the number 90).

Example 1

Input
"050043"
Output
True
Why
"05", "004", "3" are 5, 4, 3

Example 2

Input
"9080701"
Output
False

Example 3

Input
"10009998"
Output
True
Why
"100", "099", "98"

Example 4

Input
"1234"
Output
False

Constraints

  • 1 <= s.length <= 20
  • s contains only digits.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.