Given a list of strings find a new string that is lexicographically smallest and is not a substring of any of the strings in the list

Viewed 550

I'm trying to solve this by diving into two parts. First to get the lexicographically smallest values between a list of strings and then to check if it is not a substring in the given strings.

For the substring check part,

  1. Create a Set from the given list of strings to remove duplicates

  2. Set a boolean flag to true

  3. Loop through the Set and use String contains to check if the new_string
  4. If found, make flag as false and break
  5. After the end of the loop check if the flag is true
  6. If the flag is true, use this solution else go for the next value of new_string.

How do I find the list of lexicographically smallest values? I checked this to understand what lexicographically smallest means. In my case since there is a list of values should I first find the lexicographically smallest of each string and then try to find the new string which is smaller than these?

I don't need the code for it. I just want a pointer in the right direction and how should I approach this?

Note: I'm using Java

0 Answers
Related