P = (a[1] + 1) * (a[2] + 1) * … (a[n] + 1) and P <= 10^6
Let’s try to maximize value of n greedily! We can do that replacing each a[i] with lowest possible value. (ie 1).
So now P = 2 * 2 * … (let say x terms)
so, P >= 2 ^ x
ie x <= log2§
No it cannot be solved by this method. Check the test case here :
1
2
2 1 4
2 1 4
4 1 1 4
the answer should be No but your code is giving Yes.Obviously the test cases are weak.
How do I solve test cases where there can be multiple matches and if choosing one match instead of other can result in ‘no’ but choosing another match results in ‘yes’ ?
Example:
first thread: 1 2
second thread: 2 3
2 3 2 1
Result is ‘yes’ but if I choose 2 from first thread instead of second results in ‘no’.
Another example:
First thread: 1 2 4
Second thread: 3 2 4 8
4 8 4 2 2 3 1
Result is ‘yes’ only if 4 from second thread is chosen on encountering first 4 in the sequence otherwise result comes out to be ‘no’, even though the sequence is valid.
How do I solve this?