Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

Click here to see the full article post

The space complexity of Approach #2 is wrong. It should be O(N * m * n).

@Aeonaxx I have updated it. THanks.

how to deal with overflow in the recursion method?

For the first approach's time complexity, better say O(4^{N}) instead of redefining n (to what N already is).

Approach #2 is definitely wrong. We should do modulo operation on result. After modified, it'll still get TLE.

@Apolloliu I have updated the Approach #2. Its now AC. Thanks

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.