The Missing Number - Version 2
Clean -  Complexity Unknown
Currently works, explanation and further optimization in progress
module main
import StdEnv, StdLib, System.IO

:: Position :== [Int]
:: Positions :== [Position]
:: Digit :== (Char, Int)
:: Digits :== [Digit]
:: Number :== ([Char], Positions)
:: Numbers :== [Number]
:: Complete :== (Numbers, Positions)

decouple =: snd o unzip

//lcouple :: (.a -&gt; .b) (.a, .c) -&gt; (.b, .c)
lcouple fn (arg, oth) :== (fn arg, oth)

getCases :: Int *World -&gt; ([(String, [[Char]])], *World)
getCases n world
    # (range, world)
        = evalIO getLine world
    # range
        = fromString range
    # spacePos
        = elemIndex ' ' range
    | isNothing spacePos
        = abort &quot;invalid input, expected space in range\n&quot;
    # (a, b)
        = splitAt (fromJust spacePos) range
    # (a, b)
        = (toInt (toString a), toInt (toString (tl b)))
    # numbers
        = [(fromString o toString) number \\ number &lt;- [a..(b-1)]]
    # (string, world)
        = evalIO getLine world
    | n &gt; 1
        # (cases, world)
            = getCases (n - 1) world
        = ([(string, numbers) : cases], world)
    = ([(string, numbers)], world)
        
singletonSieve :: Complete -&gt; Complete
singletonSieve (list, sequence)
    | sequence_ == sequence
        = reverseSieve (list, sequence)
    = (list_, sequence_)
where
    singles :: Positions
    singles 
        = [hd pos \\ (_, pos) &lt;- list | length pos == 1]
    list_ :: Numbers
    list_
        = map (app2 (id, filter notInOtherSingle)) list
    where
        notInOtherSingle :: Position -&gt; Bool
        notInOtherSingle pos
            = not (isAnyMember pos (flatten (filter ((&lt;&gt;) pos) singles)))
    sequence_ :: Positions
    sequence_
        = foldr splitSequence sequence singles

reverseSieve :: Complete -&gt; Complete
reverseSieve (list, sequence)
    | sequence_ == sequence
        = (list, sequence)
    = (list_, sequence_)
where
    singles :: Positions
    singles
        = [hd pos \\ pos &lt;- [[subSeq \\ subSeq &lt;- sequence | isMember subSeq p] \\ (_, p) &lt;- list] | length pos == 1]
        //= [hd pos \\ pos &lt;- | length pos == 1]
    list_ :: Numbers
    list_
        = map (app2 (id, filter (\b_ = (notInOtherSingle b_) &amp;&amp; (hasContiguousRun b_)))) list
    where
        notInOtherSingle :: Position -&gt; Bool
        notInOtherSingle pos
            = not (isAnyMember pos (flatten (filter ((&lt;&gt;) pos) singles)))
        hasContiguousRun :: Position -&gt; Bool
        hasContiguousRun pos
            //= any (any (isPrefixOf pos) o tails) sequence_
            = and [isMember p (flatten sequence_) \\ p &lt;- pos]
            
    sequence_ :: Positions
    sequence_
        = foldr splitSequence sequence singles
    
splitSequence :: Position Positions -&gt; Positions
splitSequence split sequence
    = flatten (map newSplit (map (span (not o ((flip isMember) split))) sequence))
where
    newSplit :: (Position, Position) -&gt; Positions
    newSplit ([], b)
        # b
            = drop (length split) b
        | b &gt; []
            = [b]
        = []
    newSplit (a, b)
        # b
            = drop (length split) b
        | b &gt; []
            = [a, b]
        = [a]

indexSubSeq :: [Char] Digits -&gt; Positions
indexSubSeq _ []
    = []
indexSubSeq a b
    # remainder
        = indexSubSeq a (tl b)
    | isPrefixOf a (map fst b)
        = [[i \\ (_, i) &lt;- take (length a) b] : remainder]
        //= [[i \\ _ &lt;- a &amp; (_, i) &lt;- b] : remainder]
    = remainder
    
missingNumber :: String [[Char]] -&gt; [[Char]]
missingNumber string numbers
    # string
        = [(c, i) \\ c &lt;-: string &amp; i &lt;- [0..]]
    # locations
        = [(number, indexSubSeq number string) \\ number &lt;- numbers]
    # digits
        = [length (indexSubSeq [digit] [(c, i) \\ c &lt;- (flatten numbers) &amp; i &lt;- [0..]]) \\ digit &lt;-: &quot;0123456789-&quot;]
    # missing
        = flatten [repeatn (n - length i) c \\ n &lt;- digits &amp; (c, i) &lt;- [(digit, indexSubSeq [digit] string) \\ digit &lt;-: &quot;0123456789-&quot;]]
    # (answers, _)
        = until (\e = e == singletonSieve e || length [(a, b) \\ (a, b) &lt;- fst e | length b == 0 &amp;&amp; isMember a (candidates missing)] &gt; 0) singletonSieve (locations, [indexList string])
    # answers
        = filter (\(_, i) = length i == 0) answers
    = filter ((flip isMember)(candidates missing)) ((fst o unzip) answers)
where
    candidates :: [Char] -&gt; [[Char]]
    candidates chars
        = moreCandidates chars []
    where
        moreCandidates :: [Char] [[Char]] -&gt; [[Char]]
        moreCandidates [] nums
            = removeDup (filter (\num = isMember num numbers) nums)
        moreCandidates chars []
            = flatten [moreCandidates (removeAt i chars) [[c]] \\ c &lt;- chars &amp; i &lt;- [0..]]
        moreCandidates chars nums
            = flatten [flatten [moreCandidates (removeAt i chars) [ [c : num] \\ num &lt;- nums ]] \\  c &lt;- chars &amp; i &lt;- [0..]]
            
Start world
    # (number, world)
        = evalIO getLine world
    # (cases, world)
        = getCases (toInt number) world
    =  flatlines[flatten(intersperse [', '] (missingNumber string numbers)) \\ (string, numbers) &lt;- cases]

Try it online!