Our criteria is starting from the first element of ArrayList if it contains any elements of ArrayList, we have to delete checking index, such as Keys are: [ABD, AC, ABC, AD, ACD, AB]
Lets start checking,
If ABD contains any elements of this list, which is it contains both AB and AD then we will delete ABD from our List, but while checking we have to do charatacer check.
After we removed ABD new list Keys are: [ AC, ABC, AD, ACD, AB], then check if AC contains any list items... No it does not then check if ABC contains any list items, yes, AC and AB, and remove ABC as well.
Arter removing new list Keys are: [ AC, AD, ACD, AB],
Finally we will end up Keys are: [ AC, AD, AB]