Help Needed ZCO 15001

Problem: https://www.codechef.com/ZCOPRAC/problems/ZCO15001
My Submission: https://www.codechef.com/viewsolution/36060793

#include <bits/stdc++.h>
using namespace std;

int check(int arr[], int j){
	int k;
	bool ok;
	int ind;
	int ii;
	for (int i = 0; i<j; i++){
		ok = true;
		int ii = i;
		k = j;
		while (ii < k){
			if (arr[ii] == arr[k]){
				ii++;
				k--;
			}
			else{
				ok = false;
				break;
			}
		}
		ind = i;
		if (ok){
			return ind;
		}	
	}
	return -1;
}

int main(){
	int n;
	cin>>n;
	int arr[n];
	for (int i = 0; i<n; i++){
		cin>>arr[i];
	}
	if (n == 1){
		cout<<1;
		return 0;
	}
	int dp[n+1];
	dp[0] = 0;
	dp[1] = 1;
	if (arr[1] == arr[0]){
		dp[2] = 1;
	}
	else{
		dp[2] = 2;
	}
	int ind;
	for (int i = 3; i<=n; i++){
		ind = check(arr, i-1);
		if (ind == -1){
			dp[i] = dp[i-1]+1;
		}
		else{
			dp[i] = min(dp[i-1] + 1, dp[ind] + 1);
		}
	}
	cout<<dp[n];
	return 0;
}

This is my code, it is only giving me WA on one test case, I have spent hours trying to figure out what that one test case is.
Any help would be appreciated, also it would be better if any one would point out what’s wrong with my code, as I have already seen the editorial but I wanted to come up with my own working solution…
Thanks in Advance