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

Course
Course
