Can Anybody tell any Test case on which my code is Failing?Thank You So much In Advance!!
(I Have Generated Many testcases but couldn’t find one on which my code is failing).
This one -
1
13 3
1 2 2 3 4 5 6 1 2 3 4 5 6
Correct answer - 8 [(1 2 2 3 4 5 6)+(1 2 3 4 5 6)]
Your answer - 9
Note that greedy will not work here. Neither by first partitioning and then merging greedily nor by greedily partitioning the whole array.
I don’t Think Output should be 10.
For First Partition-4+2=6
For Second Partition-4+2=6
According to this Partitioning Output will be 6+6=12 and not 10
For every position in the array where there is a conflict (i.e, the frequency count of the element is more than 1), consider two cases:
You actually split the array at that point and add a new table.
You do not split and you simply increase the inefficiency of the current table.
The crux is to select the minimum value of the two cases.
Repeat the above for every conflict position.
Surely this will be of complexity N^2.
This can be improved by storing the values returned by already computed sections of the array. This is where dynamic programming helps with reducing the compute time.