Todo List Solution

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 A of size N denoting the list of the pending tasks. Each task is an integer between 1 and N. The tasks numbered from 1 to 7 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 T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains a single integer N.
  • The second line contains N space-separated integers A_1, A_2, \ldots, A_N.

Output Format

For each test case, print a single line containing one integer ― the minimum number of tasks Chef needs to complete.

Constraints

  • 1 \leq T \leq 10,500
  • 7 \leq N \leq 15
  • 1 \leq A_i \leq N for each valid i
  • A_1, A_2, \ldots, A_N are pairwise distinct

Sample 1:

Input
Output
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 8 tasks in order to finish all tasks from 1 to 7.

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;

       

       }

   }

}

}

Post a Comment

0 Comments