✅Simple C++ code ✅ O(1) Time & Space ✅
Approach\n Describe your approach to solving the problem. \nThe approach is to partition the integer n into smaller integers using only the values 3, 2, and 4, 
# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach is to partition the integer n into smaller integers using only the values 3, 2, and 4, where the goal is to maximize the product of these values. To achieve this, we prioritize using 3 as many times as possible.\n\nIf n is less than 4, we return n-1 because using a value less than 3 is not allowed, and the maximum product in such cases is achieved by subtracting 1 from n.\n\nIf n is equal to 4, we return 4 because it\'s not possible to use 3 in this case, and the maximum product is achieved by simply using 4.\n\nFor values of n greater than 4, we calculate the maximum product by using as many 3s as possible. We do this by dividing n by 3 to determine how many times we can use 3. Then, we multiply 3 to the power of this count by any remaining 2 or 4, depending on the remainder.\n\nThis approach optimizes the product by maximizing the use of 3 and multiplying it by any remaining 2 or 4. You can use an array to store powers of 3 for efficiency, as you mentioned, to reduce the time complexity.\n\n# Complexity\n- Time complexity : O(1)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n\n- Space complexity : O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n\n# Code\n```\nint p[]={1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489};\nclass Solution {\npublic:\n    \n    int integerBreak(int n) {\n       if(n<4)  return n-1;\n       else if(n==4) return n;\n       else {\n           int m=n%3;\n           if(m==0) return p[n/3];\n           else if(m==1) return p[(n/3)-1]*4;\n           else return p[(n/3)]*2;\n       }\n\n    }\n};\n```
['Math', 'C++']