From N! to N^2 (Dynamic Programming) - Part II
I tried this problem using brute-force but it was clear that it wouldn't work with an input of num=3000. Complexity for the brute-force was 3000 factorial. Instead, this was a problem similar to counting coins or solving Diophantine equations: if you manage to have all the solutions from 0..num-1, you can find the solution for num. Notice that the solution for num will require an extra loop from i=1..num where you're going to compare the current solution for num dp[num] to all solutions dp[num-i], assuming that i ends with the digit k. The two loops together lead to an num^2 solution, which runs very quick given the small num. Solution is down below, Merci, ACC. Sum of Numbers With Units Digit K - LeetCode 2310. Sum of Numbers With Units Digit K Medium 166 203 Add to List Share Given two integers num and k , consider a set of positive integers with the following properties: The units digit of each integer is k . The sum of the integers is num . Return...