| 10 | public: |
| 11 | |
| 12 | int integerBreak(int n) { |
| 13 | |
| 14 | // when n = 0,1 no possible cuts hence store 0 |
| 15 | int val[n + 1]; |
| 16 | val[0] = val[1] = 0; |
| 17 | |
| 18 | // calculate for all possible cuts possible from 1 to n |
| 19 | for (int i = 1; i <= n; i++) { |
| 20 | int max_value = INT_MIN; |
| 21 | |
| 22 | /*for n = 6 calculate for all possible cuts like maximum of |
| 23 | {(1,5),(5,1)}, {(4,2),(2,4)},{ (3,3) } |
| 24 | */ |
| 25 | for (int j = 1; j <= i / 2; j++) { |
| 26 | max_value = max(max_value, max((i - j) * j, j * val[i - j])); |
| 27 | } |
| 28 | |
| 29 | val[i] = max_value; |
| 30 | } |
| 31 | |
| 32 | return val[n]; |
| 33 | |
| 34 | } |
| 35 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected