
“4664” when read forward and backward will give the same result. Hence it is a palindrome.
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows.
The first line of each test case contains an integer ‘N’, denoting the number of bottles.
The second line of each test case contains ‘N’ space-separated integers.
For each test case, print the minimum number of times it takes to remove all bottles.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= N <= 500
1<= bottles[i] <= 1000
Time limit: 1 sec
Let’s take two pointers, i and j. I is initialized to 0 and j is initialized to N - 1.
Now if bottle[i] == bottle[i + 1]
This approach is similar to the previous approach, but here we are saving the answers in a 2-D DP array.
Since we have initially taken 2-pointers i and j, and all our recursive calls fall under the range of [i,j], it gives us an idea that all the answers to the recursive calls can be stored under a grid of size ‘N’ * ’N’ where ‘N’ is the number of bottles, Due to the fact that maximum values of i and j are ‘N’ only.
Here DP of (i,j) indicates the minimum possible answers in between the range of [i,j].
Now if bottle[i] == bottle[i + 1]