BALLOON - Editorial

another simple approach might be that we find product of first 7 natural numbers. now iterate through array and if current_element <= 7 then product /= current_element and check if product == 1 then res = i+1.
this solution is working fine but let me know if there is any case where this might cause problem.

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

ll fact(ll n) { if( n<=1 ) return n; return n * fact(n-1); }

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n,tmp,product=1,res;
	    cin>>n;
	    product = fact(7);
	    for(int i=0;i<n;i++){
	        cin>>tmp;
	        if(tmp <= 7){
	            product /= tmp;
	            if(product == 1)
	                res = i+1;
	        }
	    }
	    cout<<res<<endl;
	    
	}
	return 0;
}