6 kyu

The lost beginning

342 of 769CatPlusPlus

Description:

Problem Statement

You're given a string of digits representing a sequence of consecutive natural numbers concatenated together. Your task is to find the smallest possible first number in the sequence. The sequence starts with a single or multi-digit number and continues with numbers each incremented by 1. If multiple sequences can be formed, choose the one that starts with the smallest number.

Examples

  • "123" -> [1, 2, 3] -> 1
  • "91011" -> [9, 10, 11] -> 9
  • "17181920" -> [17, 18, 19, 20] -> 17
  • "9899100" -> [98, 99, 100] -> 98
  • "91" -> [91] -> 91
  • "121122123" -> [121, 122, 123] -> 121
  • "1235" -> [1235] -> 1235
  • "101" -> [101] -> 101

Constraints

  • Input string length: 1 - 200 characters.
  • Smallest possible first number: 1 - 1,000,000,000.

Remember, the key is to form a sequence of consecutive natural numbers. If the sequence matches the input string, you've found the smallest possible first number. Experiment with different lengths for the first number until you find a match or exhaust all possibilities.

Fundamentals
Algorithms
Strings
Mathematics

Similar Kata:

More By Author:

Check out these other kata created by CatPlusPlus

Stats:

CreatedJan 7, 2024
PublishedJan 8, 2024
Warriors Trained3761
Total Skips114
Total Code Submissions4985
Total Times Completed769
Python Completions342
Haskell Completions17
JavaScript Completions252
Java Completions100
CoffeeScript Completions7
Scala Completions12
λ Calculus Completions3
Rust Completions23
C++ Completions60
C Completions19
Total Stars122
% of votes with a positive feedback rating94% of 124
Total "Very Satisfied" Votes112
Total "Somewhat Satisfied" Votes9
Total "Not Satisfied" Votes3
Total Rank Assessments19
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • CatPlusPlus Avatar
  • JohanWiltink Avatar
  • Blind4Basics Avatar
  • pavloslav Avatar
  • Madjosz Avatar
  • o2001 Avatar
  • KayleighWasTaken Avatar
Ad