Created
May 19, 2020 03:54
-
-
Save billyfung/33ea8e643c91e511e7f50d0cf08ee6df to your computer and use it in GitHub Desktop.
dialpad interview q
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Your favorite uncle, Morty, is crazy about the lottery and even crazier about how he picks his “lucky” numbers. And even though his “never fail” strategy has yet to succeed, Uncle Morty doesn't let that get him down. | |
Every week he searches through the Sunday newspaper to find a string of digits that might be potential lottery picks. But this week the newspaper has moved to a new electronic format, and instead of a comfortable pile of papers, Uncle Morty receives a text file with the stories. | |
Help your Uncle find his lotto picks. Given a large series of number strings, return each that might be suitable for a lottery ticket pick. Note that a valid lottery ticket satisfies the following properties | |
The digits must form 7 unique numbers between 1 and 59 | |
Digits must be used in order. This means that you cannot form a number using digit n and digit n + 10, for example. Eg: In 12345678, you can't use 1 and 3 to get 13 in your lottery pick | |
Every digit must be used exactly once. This means that you cannot use one digit as a part of two different numbers. Eg: In 1234567, you can't get 12 23 3 4 5 6 7 as the lottery pick as the digit 2 is being used in both 12 and 23 | |
All the digits must be used. Eg: If the sequence is 12345679, 1 2 3 4 5 6 7 cannot be a valid lottery pick as the final digit 9 also must be used. | |
For example, given the following strings: | |
["569815571556","4938532894754","1234567","472844278465445", "0123456"] | |
Your function should return: | |
4938532894754 -> 49 38 53 28 9 47 54 | |
1234567 -> 1 2 3 4 5 6 7 | |
Note: In case when a particular string leads to more than one pick, print all the picks and use "Natural Sort order" to decide which pick to print first. | |
For example, | |
Print 2 5 23 21 4 56 7 before 25 2 3 21 4 56 7 since 2 comes before 25 according to Natural Sort order | |
Print 2 5 23 21 4 56 7 before 2 52 32 1 4 56 7 since 5 comes before 52 according to Natural Sort order |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment