Problem Statement
A string is called an increasing list if it is a comma-separated list of increasing positive integers with no leading zeroes. For example, the strings "2,3,9", "30", and "1,100,1000000000000000000000" are increasing lists, while "5,6,6", "1,2,3,", "0" and "1,02" are not.
You're given a
Definition
- Class:
- IncreasingLists
- Method:
- makeIncreasingList
- Parameters:
- String
- Returns:
- String
- Method signature:
- String makeIncreasingList(String mask)
- (be sure your method is public)
Notes
- A string S is greater than a string T lexicographically if T is a proper prefix of S, or if S has a greater character at the first position where the strings differ.
- Character ',' (comma) is lexicographically smaller than any digit ('0'-'9').
Constraints
- mask will contain between 1 and 50 characters, inclusive.
- mask will contain only commas (','), digits ('0'-'9') and question marks ('?').
Examples
"??"
Returns: "10"
There is no way to place two numbers here, so we need one two-digit number. The lexicographically smallest one is 10.
"???"
Returns: "1,2"
This mask stands for either a three-digit number or two one-digit numbers (comma-separated). Since a comma is lexicographically smaller than any digit, "1,2" is lexicographically smaller than "100".
"?????????,9"
Returns: "1,2,3,4,5,9"
The lists ends with a 9, so it can contain only one-digit numbers. It is optimal to use the smallest numbers.
"??????????,9"
Returns: "impossible"
The lists ends with a 9, so it can contain only one-digit numbers. However, the length of a list of one-digit numbers must be odd.
"?,10,?????????????????,16,??"
Returns: "impossible"
There is too much space between 10 and 16, we can only put numbers 11 to 15.
"?2?5??7,??"
Returns: "impossible"
"?2?5??7?,??"
Returns: "12,50,70,71"
"?,?566,????"
Returns: "1,1566,1567"
"???,5?????,??"
Returns: "1,2,5,6,10,11"
"???????????????????????????????,???"
Returns: "1,10,11,100,101,102,103,104,105,106"
"??9??8??7??6??5??4??3??2??1??0??"
Returns: "1,9,18,170,6005,14003,1200100000"
"?"
Returns: "1"
","
Returns: "impossible"
"0"
Returns: "impossible"
"9"
Returns: "9"
"0??????????????????????"
Returns: "impossible"
",?????"
Returns: "impossible"
"9?"
Returns: "90"
"9??"
Returns: "900"
"6?6"
Returns: "606"
"1,2??111,?000,6666666"
Returns: "1,2,1111,2000,6666666"
from Olexiy's correspondence
"1,2??111,?000,2000"
Returns: "1,20,111,1000,2000"
from Olexiy's correspondence
"??????????????????????????????????????????????????"
Returns: "1,10,100,1000,10000,100000,1000000,100000000000000"
"90,99,"
Returns: "impossible"
"?????94??8"
Returns: "1,10,94,98"
"?0???????0?????????????00?3?????7??8????0?????????"
Returns: "10,100,1000,10000,1000000,3000007,1800000000000000"
"???????????????????3??????????????6????????3??????"
Returns: "1,10,100,1000,100003,1000000,1000060,1000003000000"
"???????????????????????????????????????????????0??"
Returns: "1,10,100,1000,10000,100000,1000000,100000000000000"
"6?????????0???,???1??????????????????????????????8"
Returns: "6,10,100,10000,10010,100000,1000000,10000000000008"
"??????99????98?????97????96??????94????85?????83??"
Returns: "1,10,199,10098,100097,100960,1000940,1085000008300"
"???????????????????????????????????????????????,??"
Returns: "1,2,3,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24"
"?????5????7?????2?????2?????9????3?????7??????,???"
Returns: "impossible"
"?????5????7?????2?????2?????9????3?????7?????,????"
Returns: "1,10,50,107,108,200,202,203,900,930,1007,1008,1009"
"?????,5?????,7????,2????,2?????9????3?????7???????"
Returns: "1,2,3,5,6,10,70,71,20000,2000009,10030000,70000000"
"9?8??7??6????5????4??????3???????2????????1??????"
Returns: "9,80,7006,10050,10400,100300,1000200,100001000000"
"?9??8,?7??6,?5??4,?3??2,?1??0"
Returns: "19,28,17006,25004,33002,41000"
"???????????????????????????????????,??9??,????????"
Returns: "1,10,100,1000,1001,1002,10000,10001,10900,10000000"
"????,??,?2?0???????????????????,???05"
Returns: "1,10,11,12000,12001,12002,12003,12005"
",?????0?,????"
Returns: "impossible"
"243,03???"
Returns: "impossible"
"?8?????????"
Returns: "18,100,1000"
"?,?,9???20??9?,???"
Returns: "1,2,90,120,190,191"
"???,9????,1????,??00"
Returns: "impossible"
"??1"
Returns: "101"
"??2?????0???0?0??"
Returns: "1,2,10,100,100000"
"?0??????23?7??00???"
Returns: "10,100,123,70000000"
"?,7,??????010,?15?4?"
Returns: "1,7,10,100010,115040"
"???0???59700,?260?54"
Returns: "1,10,1059700,1260054"
"8?2?8?1?4,?209689"
Returns: "8,2080104,2209689"
"91239????1?8?717785"
Returns: "91239,100108,717785"
"?10000?0?33?73446"
Returns: "11000000,33073446"
"4610??05???9209,?050007?43"
Returns: "4610,1050009209,2050007043"
"??4?28340?34?538???767?9827?3481320196?178120?3?59"
Returns: "1,4,28340,340538,1076709827,3481320196,17812003059"
"??8??????,???"
Returns: "1,8,10,11,100"
"??????????"
Returns: "1,10,10000"
"?????????2??????????????????????????????????"
Returns: "1,10,100,200,1000,10000,100000,1000000000000"
"?0?????,?60001??06??03030??00?3???,??000?0?0??6?00"
Returns: "10,1000,1600010006,103030000003000,110000000006000"
"?,????????????0??0?0????,?9???????,?????????"
Returns: "1,10,100,100000,10000000,190000000,190000001"
"?,???????????????????????,?,???"
Returns: "impossible"
"35????1?3?5,8???"
Returns: "350,351,355,8000"
"8?,?6,93"
Returns: "80,86,93"
"????,???????1,2?"
Returns: "1,10,11,12,21,22"
"?????????????,2?"
Returns: "1,10,11,12,13,20"
"?7????4?,4?,??????"
Returns: "17,18,40,41,100000"
"?29?9??,?08"
Returns: "129,900,908"
"?7????2??2???9???,??"
Returns: "17,18,20,21,29,30,31"
"8106?54??60"
Returns: "8106,540060"
"?????90?2?????0"
Returns: "1,10,90,200,210"
"?9??,?5?0??9??9??60"
Returns: "1900,15000,90090060"
"9?,3?????7?1??"
Returns: "90,300,1070100"
"?088???0,??6?0?00"
Returns: "10880000,11600000"
"?0,?02704??00?10"
Returns: "10,102704,200010"
"804780?0?57018??7"
Returns: "80478000057018007"
"?,?????5??7????5"
Returns: "1,10,105,170,175"
"?????????????????????50???9,???,??0?5??,??????????"
Returns: "1,10,11,100,101,102,150,159,160,1000500,1000000000"
"?????????,?,????????????,???????????0?????????????"
Returns: "1,2,3,4,5,6,10,100,10000,100000,1000000,1000000000"
"????4????3???9???0??7?1????0???00???????00??,?????"
Returns: "1,2,4,10,30,190,200,701,1000,1100,1101,10000,10001"
"??????????????0?6????,????????????7?????????,????5"
Returns: "1,2,10,11,12,20,60,61,100,101,102,7000,10000,10005"
"?????1??5??3?????????0???????????2,??????,???????0"
Returns: "1,10,1005,1300,1301,2000,2001,2002,100000,10000000"
"???????????????0???????????7????????????????????0?"
Returns: "1,10,100,1000,10000,100000,700000,1000000,10000000"
"????????,?????0???0????0??????????0???????????????"
Returns: "1,10,100,100000,10000000,1000000000,10000000000000"
"??02??????????????????????????????????????????????"
Returns: "1002,10000,100000,1000000,10000000,100000000000000"
"?00??0??0??02?0??0??,????4????0?????0?300?3?0?1???"
Returns: "100,10000,1020000000,10004000000,10000300030001000"
"4?2?0?0?0?19???5?64?76??8??,860?7?2?7??2?246?583??"
Returns: "4,2000000,19000506407600800,8600702070020246058300"
"7870??0?4?4066344?9??59?,8??4738?50?29???2367?0?8?"
Returns: "7870,1004040663440900590,8004738050029000236700080"
"9000?000?00603374?207?62007?639???9?70?9?679011560"
Returns: "90000000000603374,20706200706390009070090679011560"
"8?0000000000000?0000000000010000000000000002000000"
Returns: "80000000000000000000000000010000000000000002000000"
"??????????????????????????,??,?????????????????0??"
Returns: "1,2,3,10,11,12,13,14,15,16,17,100,1000,10000,10001"
"???????????????8????????????????????0????8???,????"
Returns: "1,10,11,12,13,18,19,20,21,22,23,24,30,31,8000,8001"
"??2????????9????????????????7????,????????????,???"
Returns: "1,2,10,11,19,20,21,22,23,24,70,71,72,73,74,100,101"
"?,?,?,?,?,?,?,?,?,??,??,??,??,??,??,??,??,??,??,??"
Returns: "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20"
"???????????,??????,1????,????????,??,??????0??????"
Returns: "1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,100,1000,1001"
"???,????????8??????????0????????????,?????????,???"
Returns: "1,2,3,4,5,6,8,9,10,11,20,21,22,23,24,25,26,100,101"
"372528491815737947332878,?62???38?????6?7??32?297"
Returns: "372528491815737947332878,462000380000060700320297"
"482640764547403949260524,?3??4??7????7???3??4?1??"
Returns: "482640764547403949260524,530040070000700030040100"
"?????????????,????????????????????????????????????"
Returns: "1,10,100,1000,10000,100000,1000000,100000000000000"
"???????????????????????????????,???,??????????????"
Returns: "1,10,11,100,101,102,103,104,105,106,1000,100000000"
"0????????????????????????????????,???"
Returns: "impossible"