Input
An alphanumeric string s
.
Output
The shortest string that occurs exactly once as a (contiguous) substring in s
.
Overlapping occurrences are counted as distinct.
If there are several candidates of the same length, you must output all of them in the order of occurrence.
In this challenge, the empty string occurs n + 1
times in a string of length n
.
Example
Consider the string
"asdfasdfd"
The empty string occurs 10 times in it, so it is not a candidate for unique occurrence.
Each of the letters "a"
, "s"
, "d"
, and "f"
occurs at least twice, so they are not candidates either.
The substrings "fa"
and "fd"
occur only once and in this order, while all other substrings of length 2 occur twice.
Thus the correct output is
["fa","fd"]
Rules
Both functions and full programs are allowed, and standard loopholes are not. The exact formatting of the output is flexible, within reason. In particular, producing no output for the empty string is allowable, but throwing an error is not. The lowest byte count wins.
Test cases
"" -> [""]
"abcaa" -> ["b","c"]
"rererere" -> ["ererer"]
"asdfasdfd" -> ["fa","fd"]
"ffffhhhhfffffhhhhhfffhhh" -> ["hffff","fffff","hhhhh","hfffh"]
"asdfdfasddfdfaddsasadsasadsddsddfdsasdf" -> ["fas","fad","add","fds"]
Leaderboard
Here's the by-language leaderboard that I promised.
To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:
# Language Name, N bytes
where N
is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:
# Ruby, <s>104</s> <s>101</s> 96 bytes
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script><script>site = 'meta.codegolf',postID = 5314,isAnswer = true,QUESTION_ID = 45056;jQuery(function(){var u='https://api.stackexchange.com/2.2/';if(isAnswer)u+='answers/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJeRCD';else u+='questions/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJO6t)';jQuery.get(u,function(b){function d(s){return jQuery('<textarea>').html(s).text()};function r(l){return new RegExp('<pre class="snippet-code-'+l+'\\b[^>]*><code>([\\s\\S]*?)<\\/code><\/pre>')};b=b.items[0].body;var j=r('js').exec(b),c=r('css').exec(b),h=r('html').exec(b);if(c!==null)jQuery('head').append(jQuery('<style>').text(d(c[1])));if (h!==null)jQuery('body').append(d(h[1]));if(j!==null)jQuery('body').append(jQuery('<script>').text(d(j[1])))})})</script>