There is an input string contains only english letters, no spaces. And there is a array of words. The task is to check if it is possible to create and return output string from the input by adding spaces between the words in array. If not possible return empty string.
Ex: input="cathat", array=[rat, cat, hat] => "cat hat"
I solved it with topdown dp. (Facebook asks dp? can it be solved without dp?)
LC973 https://leetcode.com/problems/k-closest-points-to-origin/description/
Solved it with heap, I was ready to mention quickselect in case of a followup but there wasn't. Also I overcomplicated it a bit by actually computing sqrt distance but during the dry run realized that I cannot compute sqrt in my head and it wasn't necessary to do so.
PS: pass