Need help in this code :) pls help me removing my mistake

problem code = MARBLE
contest = INFI21B
my code …

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
{
// your code goes here
Scanner s = new Scanner(System.in);
int cases = s.nextInt();
while(cases–>0){
int n = s.nextInt();
String S =s.next();
String P =s.next();
char[] c1 = new char[n];
char[] c2 = new char[n];

	    for(int i=0;i<n;i++){
	      if(S.charAt(i) == '?' && P.charAt(i) == '?' ){
	          	c1[i] = 'e';
	            c2[i] = 'e';
	      }
	      else if(S.charAt(i) == '?'){
	            c1[i] = 'e';
	            c2[i] = P.charAt(i);
	        }
	      else if(P.charAt(i) == '?'){
	            c2[i] ='e';
	            c1[i] = S.charAt(i);
	        }
	        else{
	        c1[i] = S.charAt(i);
	        c2[i] = P.charAt(i);
	        }
	    }
	    
	    
	    int count =0;
	    for(int i=0;i<n;i++){
	        if(c1[i] == c2[i]){
	            count =count;
	        }
	        else if(c1[i] == 'a' || c1[i] == 'e' || c1[i] == 'i' || c1[i] == 'o' || c1[i] == 'u' ){
	            if(c2[i] == 'a' || c2[i] == 'e' || c2[i] == 'i' || c2[i] == 'o' || c2[i] == 'u'){
	            count = count + 2;
	            }
	            else{
	                count++;
	            }
	        }
	        else if(c1[i] == 'b' || c1[i] == 'c' || c1[i] == 'd' || c1[i] == 'f' || c1[i] == 'g' || c1[i] == 'h' || c1[i] == 'j' || c1[i] == 'k' || c1[i] == 'l' || c1[i] == 'm' || c1[i] == 'n' || c1[i] == 'p' || c1[i] == 'q' || c1[i] == 'r' || c1[i] == 's' || c1[i] == 't' || c1[i] == 'v' || c1[i] == 'x' || c1[i] == 'y' || c1[i] == 'z' ){
	            if(c2[i] == 'b' || c2[i] == 'c' || c2[i] == 'd' || c2[i] == 'f' || c2[i] == 'g' || c2[i] == 'h' || c2[i] == 'j' || c2[i] == 'k' || c2[i] == 'l' || c2[i] == 'm' || c2[i] == 'n' || c2[i] == 'p' || c2[i] == 'q' || c2[i] == 'r' || c2[i] == 's' || c2[i] == 't' || c2[i] == 'v' || c2[i] == 'x' || c2[i] == 'y' || c2[i] == 'z'   ){
	            count = count + 2;
	            }
	            else{
	                count++;
	            }
	        }
	    }
          System.out.println(count);
	}
}

}

I have seen editorial coz I was stuck with same issue

So, instead of choosing any specific alphabet to replace ? we have to simply iterate through all alphabets from a to z and check the least number of conversions when ? is replaced in each iteration

TLE?? Even when we iterate through all alphabets time complexity remains O(26*n) so it won’t be issue

3 Likes

Hi @ayushkr07

This video was helpful for me in understanding this, I thought you’d find it helpful too.
https://youtu.be/yFzPb1wtxEY

1 Like