Ninja is given an integer ‘N’ . One day Ninja decides to break the integer into K positive parts (K>=2) such that the sum of all parts is equal to ‘N’.Ninja wants to maximize the product of all the ‘K’ parts.
Help Ninja in helping what maximum possible product it can obtain by breaking the integer ‘N’ into ‘K’ positive parts where ‘K’ can be any integer greater than 2.
Input Format:
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first and only line of the test case consists of a single integer ‘N’.
Output Format:
Return the maximum possible product Ninja can obtain by breaking integer ‘N’ into ‘K’ parts.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= ‘T’ <= 11
2 <= ‘N’ <= 55
Time Limit: 1 sec
The approach would be to think the max product that we could get on breaking a number N into two factors. This product can be represented by the following function : f = x(N-x).
The maximum of this fu...read more
The main idea is to break the given integer ‘N’ into all possible ways and out of all possible ways the one with the maximum product will be the answer.
Algorithm:
- Create a recursive functi...read more
In Approach 1 there are many overlapping sub-cases Hence we will apply memoization in Approach 1 to avoid calculating sub-problems many times.
In the above sub-tree, we are calculat...read more
The main idea is to use the observation when the given number is broken into 2 and 3’s will give a maximum answer. If n%3 == 0 it means that the given number is a multiple of 3 hence b...read more
Top Info Edge Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Info Edge Software Engineer
Reviews
Interviews
Salaries
Users/Month