File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed 
com/hackerrank/algorithms/implementation Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 1+ package  com .hackerrank .algorithms .implementation ;
2+ 
3+ import  java .util .Scanner ;
4+ 
5+ /** 
6+  * Created by ramswaroop on 02/05/2016. 
7+  */ 
8+ public  class  GridSearch  {
9+ 
10+     public  static  void  main (String [] args ) {
11+         Scanner  in  = new  Scanner (System .in );
12+         int  t  = in .nextInt ();
13+         for  (int  a0  = 0 ; a0  < t ; a0 ++) {
14+             int  R  = in .nextInt ();
15+             int  C  = in .nextInt ();
16+             String  G [] = new  String [R ];
17+             for  (int  G_i  = 0 ; G_i  < R ; G_i ++) {
18+                 G [G_i ] = in .next ();
19+             }
20+             int  r  = in .nextInt ();
21+             int  c  = in .nextInt ();
22+             String  P [] = new  String [r ];
23+             for  (int  P_i  = 0 ; P_i  < r ; P_i ++) {
24+                 P [P_i ] = in .next ();
25+             }
26+             int  count  = 0 ;
27+             int  start  = 0 ;
28+ 
29+             loop1 :
30+             for  (int  G_i  = 0 ; G_i  < R ; G_i ++) {
31+                 if  ((start  = G [G_i ].indexOf (P [0 ], start )) > -1 ) {
32+                     count  = 1 ;
33+                     for  (int  P_i  = 1 ; P_i  < r  && G_i  + P_i  < R ; P_i ++) {
34+                         if  (G [G_i  + P_i ].indexOf (P [P_i ]) != start ) {
35+                             break ;
36+                         }
37+                         count ++;
38+                     }
39+                     if  (count  == r ) {
40+                         System .out .println ("YES" );
41+                         break ;
42+                     } else  {
43+                         continue  loop1 ;
44+                     }
45+                 }
46+             }
47+             if  (count  != r ) {
48+                 System .out .println ("NO" );
49+             }
50+         }
51+     }
52+ }
53+ 
Original file line number Diff line number Diff line change 1111 * @date: 6/26/15 
1212 * @time: 5:34 PM 
1313 */ 
14- public  class  ConstructTreeFromInOrderAndPreorder  {
14+ public  class  ConstructTreeFromInOrderAndPreOrder  {
1515
1616    public  <E  extends  Comparable <E >> void  constructTreeWithInOrderAndPreOrder (List <BinaryNode <E >> inOrder ,
1717                                                                              List <BinaryNode <E >> preOrder ) {
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments