Uncle-Morty-s-Lottery-Picks

Winning Ticket!

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 must have 7 unique numbers between 1 and 59, digits must be used in order, and every digit must be used exactly once.

For example, given the following strings:

[ "569815571556", “4938532894754”, “1234567”, “472844278465445”]

Your function should return:

4938532894754 -> 49 38 53 28 9 47 54 1234567 -> 1 2 3 4 5 6 7

Logic to the solution: The number is passed as a string at the beginning . validate() function validates the length of the string which in turn goes through parses the string (parseStr function) and removeDuplicates function to give the end result Get all the pair combinations of the string: For eg: 4798 will give 47,79,98. If length of the string < 7 -> INVALID = 7 & not a zero , is unique and <59 -> OUTPUT >7 -> passes through a logic explained below

  Taking two consecutive elements (val1,val2) at a time,
  Scenario 1 : If val1 <val2 && val1 <59 ---> retain val1 and discard val2
  Scenario 2 : If val1< val 2 && val1>59 ----> Split val1 and take first digit, discard val2
  Scenario 3: If val1 >val2 && val1 <59 ----> retain val1 
  Scenario 4 : If val1> val 2 && val1>59 ----> Split val1 and take first digit, discard val2

Parse the result to check for the length again : if >7 , aggregate the adjacent single digits to double until length is 7. else , split the double digits until length is 7.

Check the result from parsing to make sure there are no duplicates.