Skip to main content
All Questions

Find the minimum original configuration containing a corrupted digit string.

Unlock detailed company stats for this questionUpgrade

Given config, a string of digits (0-9) representing a corrupted configuration, and integers x and y (1 <= x, y <= 9). The original configuration was generated by starting with cur = 0 and repeating any number of times: add either x or y to cur, then append (cur % 10) to the string. Some digits were later deleted, producing config. Reconstruct the minimum possible decimal value of an original configuration such that config is a subsequence of it and the first digit is x % 10 or y % 10. If none exists, return "-1". Example 1: config = "27", x = 2, y = 3 gives 247 (257 is also valid). Example 2: config = "521", x = 5, y = 5 gives -1 (only digits 5 and 0 are possible). Example 3: config = "05", x = 5, y = 5 gives 05 (leading zero allowed). Example 4: config = "88", x = 2, y = 4 gives -1.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.