Skip to main content
All Questions

Restore the minimum-value server configuration from a corrupted digit string.

Unlock detailed company stats for this questionUpgrade

Starting from x or y, repeatedly add x or y to the current value and record cur % 10 as the next digit of the configuration. Some recorded digits were erased, leaving the string config; the first character of config equals x or y. Find the final configuration with the minimum decimal value from which config can be obtained by removing digits (config is a subsequence of it), or return "-1" if impossible. Examples: config = "27", x = 2, y = 3 gives "247"; config = "324", x = 2, y = 3 gives "36924"; config = "521", x = 5, y = 5 gives "-1". Constraints: 2 <= |config| <= 2*10^5, 1 <= x, y <= 9. Hint used: BFS over (unit digit, matched index) with validity prechecks.

Format · Amazon SDE-2 OA.

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.