fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. int t; //test case variable
  6. cin>>t; //input test case
  7. while(t--){ //loop for the whole code to run t times
  8. int n,i,flag=0,x;
  9. cin>>n; //input the size of the array
  10. int a[1000]={0}; //set all the array values to null
  11. for(i=0;i<n;i++){ //enter all the values i.e 1,2,3,3 for the given test case
  12. cin>>x; //enter the values one by one
  13. if(a[x+1]==0){ //check wether the values can be stored in the genie seq or not
  14. a[x+1]=1; //from left to right //set the value at that place=1(means it can be entered)
  15. flag++; //increase the counter
  16. }else if(a[n-x]==0){ //check wether the values can be stored in the genie seq or not
  17. a[n-x]=1; //from right to left
  18. flag++; //set the value at that place=1(means it can be entered)
  19. }//increase the counter
  20. }
  21. if(flag==n){ //if counter=size of array(it means all values are placed
  22. cout<<"YES"<<endl; //and genie seq can be formed)
  23. }else{ //if counter!=size of array(it means all values are not placed
  24. cout<<"NO"<<endl; //and genie seq can't be formed)
  25. }
  26. }
  27. }
Success #stdin #stdout 0.01s 5472KB
stdin
1
6
5 4 2 3 1 5 
stdout
YES