Problem
Chef has made a To-Do list: a list of all the pending tasks that he has to complete. The list is in the increasing order of time taken to finish the tasks. Chef begins from the starting of the list.
Given an array of size denoting the list of the pending tasks. Each task is an integer between and . The tasks numbered from to are classified as top priority tasks. Chef needs to know the minimum number of tasks he has to complete in order to get all the top priority tasks accomplished. Can you help him to do so?
Input Format
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains a single integer .
- The second line contains space-separated integers .
Output Format
For each test case, print a single line containing one integer ― the minimum number of tasks Chef needs to complete.
Constraints
- for each valid
- are pairwise distinct
Sample 1:
3 9 1 5 2 4 9 3 6 7 8 7 7 4 3 6 5 2 1 10 10 9 8 7 6 5 4 3 2 1
8 7 10
Explanation:
Test case 1: Chef needs to complete the first tasks in order to finish all tasks from to .
Test case 2: Chef needs to finish all the tasks as all of them are top priority.
Program :
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc =new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
int m=0;
int n=sc.nextInt();
int a[]=new int[n];
for(int j=0;j<n;j++)
{
a[j]=sc.nextInt();
}
for(int j=0;j<n;j++)
{
if(a[j]>=1&&a[j]<=7)
m=m+1;
if(m==7)
{
System.out.println(j+1);
break;
}
else
continue;
}
}
}
}
0 Comments