This is the code that I submitted for RANGEASSIGN problem in starters 64 but it could pass only 3 out of 5 test cases. Please tell me what I am missing here. Thanks
#include <iostream>
using namespace std;
bool helper(int n, int arr[]){
int start = arr[0];
int end = arr[n-1];
if(start==end) return true;
int lastStartIdx = 0, firstEndIdx = n-1;
for(int i=0;i<n;i++){
if(arr[i]==start) lastStartIdx = i;
}
for(int i=n-1;i>=0;i--){
if(arr[i]==end) firstEndIdx = i;
}
if(firstEndIdx<lastStartIdx || lastStartIdx+1==firstEndIdx) return true;
return false;
}
int main() {
int t;cin>>t;
while(t--){
int n;cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
if(helper(n,arr)) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
// your code goes here
return 0;
}