Recursion implementation to find the optimal playlist of a given list of words