Two questions on Hackerank. The time given is 90 min and I submitted in 1h.
- Given a list of clothing items [A, B, C, ...] and a list of illegal outfits [[A, B], [A, C], ...], return the number of legal outfit combinations. A combination has to have at least 1 outfit and must not contain any illegal combination.
- I used backtracking to solve it. Thought my solution was super inefficient but it passed all the test cases.
- Word w is called to have been derived from word v if w can be obtained by deleting exactly one character from v. For example, "caaw" is derived from "caw". In this case, these two words are said to have the same meaning. Given a list of words, such as ["caw", "caaw", "caww", "hoot", "hooot", "chirp"], return the number of distinct meanings. (In this example it would be 3.)
- This problem can be divided into two parts: first, using a two pointer approach to compare each pair of words. If two words have the same meaning, add an edge between them; then, use DFS to find the number of connected component in the graph.
Please comment below how you would solve them!