The problem asks us to return our answer modulo (10^9)+7, which is a good sign that we will not be able to brute force this. Dynamic Programming + Sliding Window The idea is to build up a dp array, where dp[i] represents the number of new sharers on that day. We store new sharers for dp because if we had stored total sharers instead, we could not calculate dp[i] based on dp[i-1] since some of the…
Brute Force Brute force is a possible solution because the domain of n is small: 2 Time Complexity: O(n) Space Complexity: O(1) Iterative The idea is to check each digit of n, starting with the rightmost digit or the ones place. If the digit is zero, then we can split that into 1 * (magnitude of the digit) and 9 * (magnitude of the digit). If the digit is one, then we can split it into 2 * and 9 *…