---
title: "Comment by Amr Saber on \"How to Solve the Staircase Problem with JavaScript using Memoization\" | Hashnode"
description: "The order of the old implementation is not O(n^3) it&#39;s O(3^n) as you branch 3 times for each call, and you have total n different cases, so it&#39;s 3 * 3 *"
url: "https://hashnode.com/posts/how-to-solve-the-staircase-problem-with-javascript-using-memoization/62c8bcbde62bf98e0fb06a4a/comment/62c8c7b2e62bf98e0fb06b25"
---

[Discussion](https://hashnode.com/posts/how-to-solve-the-staircase-problem-with-javascript-using-memoization/62c8bcbde62bf98e0fb06a4a)

Comment [How to Solve the Staircase Problem with JavaScript using Memoization](https://hashnode.com/posts/how-to-solve-the-staircase-problem-with-javascript-using-memoization/62c8bcbde62bf98e0fb06a4a)

[Amr Saber](https://hashnode.com/@amr-saber)

[Jul 9, 2022](https://hashnode.com/posts/how-to-solve-the-staircase-problem-with-javascript-using-memoization/62c8bcbde62bf98e0fb06a4a/comment/62c8c7b2e62bf98e0fb06b25)

The order of the old implementation is not O(n^3) it's O(3^n) as you branch 3 times for each call, and you have total n different cases, so it's 3 \* 3 \* 3 \* 3 ... n times which is 3^n.

[Amit Mehta](https://hashnode.com/@apmfree)

[Jul 9, 2022](https://hashnode.com/posts/how-to-solve-the-staircase-problem-with-javascript-using-memoization/62c8bcbde62bf98e0fb06a4a/comment/62c8c7b2e62bf98e0fb06b25#reply-62c8da3abffc4694f5bc0efb)

Kudos for catching that! 👍
