Overview
You will be given a list of strings. If any two elements are equal, you can delete both of them. If one element a is a substring of element b, you can delete a and split b into two parts, having excluded a from it.
For example, below are all legal operations:
["a", "a"] -> []
["cash", "as"] -> ["c", "h"]
["cash", "ca"] -> ["sh"]
Note that if the substring is a prefix / a suffix of the other string then you only end up with 1 element instead of 2.
Furthermore, if a substring occurs more than once in a longer string, it can be broken at either point.
["tester", "t"] -> ["ester"] or ["tes", "er"]
Objective
Given a list of of strings, reduce all the strings such that the longest remaining string is of minimum length. Your goal is to output this length.
Rules
- All strings will be lower case and will contain only letters a-z with no spaces or any other characters.
- There will be between 0-100 strings
- Each string will be 1-100 characters long
Test Cases
[] -> 0
["a"] -> 1
["a", "a"] -> 0
["a", "a", "a"] -> 1
["ab", "a"] -> 1
["cat", "a", "at"] -> 1
["cat", "t", "at"] -> 1
["heart", "hear", "bear", "art", "he", "b", "h"] -> 0
["heart", "ear", "h", "t"] -> 0
["heart", "ear"] -> 1
["heart", "cart", "mart", "art"] -> 4
["a", "abcde", "bcde", "cde", "de", "e"] -> 1
["element", "e"] -> 4
["element", "e", "e"] -> 2
["fastest", "t", "fas", "est"] -> 0
["lovely", "l", "love"] -> 1
["fastest", "t", "fastes"] -> 0
["aaaaaaa", "a", "a", "a", "a", "a", "a", "a"] -> 0
["cabababababa", "bab", "caba", "ababa"] -> 0
["baby", "b", "aby"] -> 0
Worked example
["heart", "hear", "bear", "art", "he", "b", "h"]
["heart", "ear", "bear", "art", "he", "b"]
["heart", "ear", "ear", "art", "he"]
["heart", "art", "he"]
["art", "art"]
[]
Code golf rules / scoring.
["element", "e"]? \$\endgroup\$["cat", "t", "at"] -> 0- should that be1? \$\endgroup\$["element", "e"] -> 4and["element", "e", "e"] -> 2? I understand the first one, but I dunno how we go from 4 (i.e.lmnt) to 2. \$\endgroup\$["a", "abcde", "bcde", "cde", "de", "e"]should also be1\$\endgroup\$