Password From Ordering Hints
Problem statement
Each string in hints lists distinct password characters in their required relative order. The password contains every distinct character that appears in any hint exactly once.
Return the lexicographically smallest password consistent with every hint. Return the empty string when the hints contain a cycle and no valid password exists.
Function
deducePassword(hints: String[]) → StringExamples
Example 1
hints = ["wrt","wrf","er","ett","rftt"]return = ""Combining adjacent constraints yields the unique order wertf.
Example 2
hints = ["ab","ba"]return = ""The two hints require both a before b and b before a.
Constraints
1 <= hints.length <= 10000- Each hint contains 1 to 62 distinct letters or digits.
- At most 62 distinct characters appear overall.