It looks as though you're approaching this problem *greedily*. You're going through the topics, one at a time, and if a topic has a new first word *or* a new second word, then you're deciding that must be one of the original topics.
However, that won't necessarily give the right answer. Original topics don't have to come first on the sign-up sheet. For example, imagine if you had two real topics: a b c d Now let's construct all possible topics from those two originals. a b a d c b c d Your algorithm will see the bolded lines in the following as new, because either the first word or the second word hasn't been seen before: *a b* *a d* *c b* c d It will say 1 could be invented, but in fact 2 could be -- if a b and c d are the original topics. That isn't the only possible set of original topics -- for example, a d, c b -- as long as your original set of topics *covers* all the first and last names. I don't have a sense for how experienced you are as an algorithmic problem solver. If the phrase "find the minimum edge cover on a bipartite graph" isn't too intimidating, then dive right in, and maybe look at the analysis (on the same page as the problem; look for "Contest Analysis" on the left-hand side) if you need help. If you're relatively new, and I don't know whether you are, here's my generic advice: 1. Solve Problem A from as many Qualification Rounds and Kick Starts as you can. 2. Solve Problem A from as many Round 1A,1B,1C as you can. 3. Solve Problem B from as many Qualification Rounds and Kick Starts as you can. 4. Solve problem B from as many Round 1A,1B,1C as you can. Then move on to A from Round 2, and start hunting around for stuff it seems like you could figure out from the rest of the problems (starting with easier problems from earlier rounds). Best of luck! Bartholomew On Tue, Sep 4, 2018 at 10:15 AM NIRZAR AMBADE <[email protected]> wrote: > import java.io.*; > import java.util.*; > > public class Test1 { > > public static void main(String[] args) throws NumberFormatException, > IOException { > // TODO Auto-generated method stub > BufferedReader inp=new BufferedReader(new > InputStreamReader(System.in)); > int T=Integer.parseInt(inp.readLine()); > for(int k=0;k<T;k++) > { > int duplicateWords=0; > int lines=Integer.parseInt(inp.readLine()); > String [] words=new String[lines]; > HashMap<String, Integer> FirstwordCount=new > HashMap<String,Integer>(); > HashMap<String,Integer> SecondwordCount=new > HashMap<String,Integer>(); > for(int i=0;i<lines;i++) > { > Boolean First=true; > Boolean Second=true; > words[i]=inp.readLine(); > if(!FirstwordCount.containsKey(words[i].split(" ")[0])) > { > FirstwordCount.put(words[i].split(" ")[0], 1); > First=false; > } > if(!SecondwordCount.containsKey(words[i].split(" ")[1])) > { > SecondwordCount.put(words[i].split(" ")[1], 1); > Second=false; > } > if(First==true && Second==true) > { > duplicateWords++; > } > } > System.out.println("Case #"+(k+1)+": "+duplicateWords); > } > > > } > > > } > > Can someone let me know in which scanrio i am failing . > https://code.google.com/codejam/contest/11254486/dashboard#s=p2&a=3 link > to the question. > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-code/6bb12b1f-fa6d-438f-94f2-4fe74095708f%40googlegroups.com > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/CAHaiWHOGqTyD0FZOmtmdwCrSrCns5d8_V53Lt4UW_1dOHuy2%3Dw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
