Garage Door Code
InterviewTime limit4sMemory limit1024 MB
Find every K-digit code that appears as a subsequence of each observed keypad entry, and print them in sorted order.
- Level
Easy3 of 10
- Topics
- Brute force, String matching, Implementation
- Solved
- No attempts yet
Problem
There have been an increasing number of laptop thefts in your area lately. After yours was recently stolen too, you decided you had had enough and were going to do something about it. After asking around, you heard some rumors about where the stolen laptops have been hidden, and you want to get your laptop back.
The rumors led you to a particular garage, and you decided to keep an eye on it to figure out how to get in. Over the course of the afternoon, you saw a handful of people come, enter the garage, and then leave.
There is a security keypad on the door. As you watched carefully, you noticed different people entering different numbers of digits. Some, maybe all, of them seem to be pretending to intersperse extra key presses just to confuse anyone watching them. The keypad manufacturer's webpage says the keypad was designed to use codes with a predetermined length of digits. Given observations of different individuals entering elongated variations of the code (each one contains the correct code), can you determine what the correct code is? It is guaranteed that at least one correct code matches all observations. There may be more than one matching code, and you must find all of them.
Input
The first line of input contains two integers (), the number of digits specified by the manufacturer for a correct code, and (), the number of elongated entry code sequences that you observed.
Each of the next lines contains a string of at least and at most 12 digits (0-9). These are the elongated entry code sequences that you have observed.
Output
Determine all -digit codes that match the full set of elongated observations.
On the first line, output , the number of codes that match the set of elongated observations. Then output lines, each containing one of these matching codes, sorted in increasing lexicographic order.