#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve()
{ ll n,x;
cin>>n;
vector v(7) ;
ll a[n];
for (int i = 1; i <=n; i++) cin>>a[i];
for (int i = 1; i <=n; i++)
{ if( a[i]==1 || a[i]==2 || a[i]==3 || a[i]==4 || a[i]==5 || a[i]==6 ||a[i]==7 )
v.push_back(i);
}
x= *max_element(v.begin(), v.end());
Can there be more than one occurences of the same number in the entire array? like for example: 1 2 3 4 5 19 2 45 99 7 6? what will be the output of this test case? Also, can we get a list of test cases for this challenge!
int main() {
int t,n,i,flag=0;
cin>>t;
while(t–){
cin>>n;
long long int a[n];
for(i=0;i<n;i++){
cin>>a[i];
if(a[i] ==1 or a[i] ==2 or a[i] ==3 or a[i] ==4 or a[i] ==5 or a[i] ==6 or a[i] ==7 )
flag++;
if(flag == 7)
{ cout<<i+1<<endl;
break ;} } }
it clearly written in the problem statement we have solve all question which are in between before [1,7] suppose for this test case
8 7 6 5 4 3 2 1
8 is coming before any number so we have to solve it in order move forward int the array.
so the min ques what we have to solve in order to make VIBGYOR is 8.
and this case
7 4 3 5 6 1 8 2 9
and this case as you can see 7 is coming at first then 4,3,5,6,1,8 and then 2 .
so we have to solve min of 8 ques to form VIBGYOR.
bro its provided in the question that the input array is pairwise distinct. Does that mean that there will be no duplicate elements?..i tried to process the elements while taking them as input…so if the value of count==7, i break the loop and return k, which the counter for the outer loop…my solution is getting WA…ps help
nothing much different .If you are going with the first approach,then what you have to do is that you have to include a header file of c++i.e #include
and in the next line you have to write using namespace std;
further your code will be same .Just you have to do the following replacement
scanf ->cin>>
printf-> cout<<
Other than this your whole code will be same
one advise:-you should learn c++ language ,as it is effiecient as compared to the c language
Thanks for asking