0

I am currently doing a coding challenge at codesignal, challenge name is commonCharacterCount, I have kind of made the logic below , but after troubleshooting for some time I can see the if statement is not running at all, I am not sure what the reason behind as both the typesS1Array[x]and S2Array[i] are of String.

Any hint on this please , what I am missing here.

int commonCharacterCount(String s1, String s2) {
    
    String[] S1Array= s1.split("");
    String[] S2Array= s2.split("");
    
    int count=0;
 
    for(int x=0;x<S1Array.length;x++){
 
        // S2ArrayCopy is to check if the S2Array's array element is already been checked using 1 and 0, if 1 then count will not be updated as already checked
            int[] S2ArrayCopy= new int[S2Array.length ] ;
            Arrays.fill(S2ArrayCopy,0);
 
        for(int i=0;i<S2Array.length;i++){
          
              
                             
            if(S1Array[x] == S2Array[i] && S2ArrayCopy[i] != 1 ){
                              

                 count++;
                
               S2ArrayCopy[i]=1;
                
                break;
            }
            
            
            
        }
        
        
    }
umair
  • 95
  • 8
  • Unrelated: learn about java naming conventions. Fields and variables go camelCase. And make them meaningful for your readers. So instead of calling it S1Array, why not `s1Elements` or something. No need denote the **type** array in the name! – GhostCat Mar 12 '21 at 11:32
  • And then: you want others to spend their free time to help you with your problem. So you want to make that as easy as possible. One important aspect: please spend the time to properly format/indent your code. All those empty lines and broken indenting for your loops ... that is **noise**. It makes it harder to read your input. (not only for us, also for you yourself). So: always take care about that. A professional keeps his work area clean at all time. – GhostCat Mar 12 '21 at 11:34
  • @GhostCat Thanks for the feedback, I am learning new things everyday and got some good points from you so will keep in mind. Also thanks for recommending the naming convention here, I got your point – umair Mar 12 '21 at 20:35

0 Answers0