this is my code for “your name is mine” please tell me why my answer is rejected though my output is right?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
//your name is my name
class name {
public String str_a,str_b;// string var to store the two strings
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
name obj=new name();
System.out.println("enter the two strings\n");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
obj.str_a=br.readLine();
obj.str_b=br.readLine();
obj.func_x(obj.str_a);
}catch(IOException e){
e.printStackTrace();
}
}
void func_x(String str_a){// this function maintains an index counter,dat contains the index of the matched charecter
int index=0;
int i=0;
while(i<str_a.length()){
index=func_y(index,str_a.charAt(i));
if(index!=-1){
index++;
i++;
}
else
break;
}
if(i!=str_a.length())
System.out.println("NO");
else
System.out.println("YES");
}
int func_y(int start_index,char k){
for(int i=start_index;i<str_b.length();i++){// as the charecters have 2 appear in order,if the matching charecter
// is found its index is returned and search for the next valid charecter is started from the index value prev
// returned
if(k==str_b.charAt(i))
return(i);
}
return(-1);
}
}