Help me in solving TRIPLETMIN problem

My issue

My code



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



int main()
{
    int t;
    cin>>t;
    int n;
    while(t--)
    {
   
    } 
    return 0;
}

Problem Link: TRIPLETMIN Problem - CodeChef

Hi Shubh, I looked at the problem statement it is a bit confusing . Down below is my bruteforce way of solving this problem. This solution is not the optimal solution but I have built a logic for this problem. By the way if you dont understand what the problem wanted you to do then i can explain that.

my code goes here:

include <stdio.h>
int min_oftriplet(int index,int ar[], int size)
{
//first we sort the arrAY.
int n=size;
for(int i=1;i<=n;i++)
{
int temp;
for(int j=i+1;j<=n;j++)
{
if(ar[i]>=ar[j])
{
temp=ar[i];
ar[i]=ar[j];
ar[j]=temp;
}
}
}
//after sorting we find the minimum possible number in the triplet.
if(index>n){

       return ar[1];  //if query is greater than the size                 of array return the smallest                       number .
    }else                        
    {
      for(int i=1;i<=index;i++)
      {
        if(i+2>=index)
        {
          return ar[i];
        }
      }
 	}
}

int main(void) {

int t;
scanf("%d",&t);


while(t--)
{
    int n,q;
    scanf("%d %d",&n,&q);
    int ar[n],quer[q];
    
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&ar[i]);
    }
    for(int i=1;i<=q;i++)
    {
        scanf("%d",&quer[i]);
    }
    for(int i=1;i<=q;i++)
    {
    printf("%d\n",min_oftriplet(quer[i],ar,n));
    }
}

return 0;

}