Codechef June Cook-Off 2021 Solution | ICPC Balloons (BALLOON) | AskTheCode
Problem:
Chef is participating in an ICPC regional contest, in which there is a total of N problems (numbered 1 through N) with varying difficulties. For each valid i, the i-th easiest problem is problem Ai.
After a team solves a problem, a balloon with a colour representing that problem is tied next to their desk. Chef is fond of colours in VIBGYOR, which are representative of the problems with numbers 1 through 7. The remaining problems have their own representative colours too.
Find the minimum number of problems which Chef's team needs to solve in order to get all the balloons for problems 1 through 7 (and possibly some other balloons too) tied next to their desk, if you know that Chef's team knows the difficulties of all problems and solves the problems in increasing order of difficulty.
Input:
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 A1,A2,…,AN.
Output:
For each test case, print a single line containing one integer ― the minimum number of problems Chef's team needs to solve.
Sample Input:
3
7
1 2 3 4 5 7 6
8
8 7 6 5 4 3 2 1
9
7 4 3 5 6 1 8 2 9
Sample Output:
7
8
8
EXPLANATION:
Example case 1: Since there are a total of 7 problems, Chef's team will have to solve all of them.
Example case 2: Problems 1 through 7 appear among the first 8 problems.
Example case 3: Problems 1 through 7 again appear among the first 8 problems.
Code:
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef{
public static void main (String[] args) throws java.lang.Exception{
HashMap<Integer,Integer> hm = new HashMap<>();
hm.put(1,0);
hm.put(2,0);
hm.put(3,0);
hm.put(4,0);
hm.put(5,0);
hm.put(6,0);
hm.put(7,0);
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
String r;
int n,remaining,res;
while(t>0){
remaining=7;
res=0;
n = sc.nextInt();
while(remaining>0){
if(hm.containsKey(sc.nextInt())) remaining--;
res++;
}
System.out.println(res);
if(res!=n) r=sc.nextLine();
t--;
}
}
}
Comments