Friday, 17 July 2015

Marut and Girls : bookmyshow

https://www.hackerearth.com/bookmyshowhiringchallenge/problems/
package com.thread.dp;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

class TestClass {
       public static void main(String args[] ) throws Exception {
              /* Read input from stdin and provide input before running */
              int count = 0;
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              String line = br.readLine();
              int N = Integer.parseInt(line);
              Set<String> qualitiesNds = new HashSet<String>();
              String line1 = br.readLine();
              for(String str : line1.split(" ")) {
                     qualitiesNds.add(str);
              }
              line1 = null;
              int proposals = Integer.parseInt(br.readLine());
              for (int i = 0; i<proposals; i++) {
                     String[] qualities = br.readLine().split(" ");
                     Set<String> quality = new HashSet<String>();
                     for(String itm : qualities) {
                           if(qualitiesNds.contains(itm)) {
                                  quality.add(itm);
                           }
                           if(N==quality.size()) {
                                  break;
                           }
                     }

                     if(N==quality.size()) {
                           ++count;
                     }
              }
              System.out.println(count);
       }
}


No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...