Thanks @NathanMerrill for allowing me to post this! The following is entirely his wording from this sandbox post (deleted):
We define a "Fresh" substring as a substring that is different from any other substring that starts earlier.
For example, if I take the string "abababc"
and split it: ["ab","ab","a","bc"
], the first and the last substring are fresh, but the middle two are not, because they can be found earlier in the string.
For this challenge, you need create a list of the smallest possible fresh substrings for each position in the string. If there are no fresh substrings, output and empty list or empty string, etc.
For example, if you were passed "ABABCBA"
, you should return ["A","B","ABC","BC","C"]
.
Test Cases:
ABABCBA A,B,ABC,BC,C, // ABC instead of AB because there is an AB earlier in the string
AAAAAAA A,,,,,,
ABCDEFG A,B,C,D,E,F,G
ABDBABDAB A,B,D,BA,ABDA,BDA,DA,,
ACABCACBDDABADD A,C,AB,B,CAC,ACB,CB,BD,D,DA,ABA,BA,AD,,
The empty items are not mandatory.
Aa
can we returnA,a
orA
?If there are no fresh substrings, then it shouldn't be included in the list.
: Can we have an empty item at that position in the list? \$\endgroup\$ABCDEEFG
->ABCDEFG
? \$\endgroup\$D
is where you believeDD
to be:smallest possible fresh substrings for each position in the string
\$\endgroup\$A,C,AB,B,CAC,ACB,CB,BD,D,DA,ABA,BA,AD
for the last test caseCBD
is greater asCB
andCB
is not earlier in the string \$\endgroup\$