Apple interview question

Leetcode medium based on backtracking and string