We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Actually, a similar solution works fine, without any need for DP, memoization, or graph search. Filter array for actual factors of n, reverse sort. Then try them one by one, rejecting any that don't lead to a solution:
Reverse Factorization
You are viewing a single comment's thread. Return to all comments →
Actually, a similar solution works fine, without any need for DP, memoization, or graph search. Filter array for actual factors of n, reverse sort. Then try them one by one, rejecting any that don't lead to a solution:
Then format the result to give the desired answer. The first valid solution found will be the shortest lexicographically due to the reverse sort.