String window in hashing trie challenge

why iit give run time error or in one test cases it give wrong answer ??
import java.util.*;
public class Main {
public static void main(String args[]) {

  Scanner kb=new Scanner(System.in);
  String s1=kb.nextLine();
  String s2=kb.nextLine();

  HashMap<String,Integer> map=new HashMap<String,Integer>();
  int min=1000000;
  String st="";
  
  for(int i=0;i<s1.length();i++)
    {
		for(int j=i+1;j<=s1.length();j++)
		  {
			 String s4=s1.substring(i,j);
			boolean ans=contain(s4,s2) ;
			 
			 if(ans)
			    {
				  if(s4.length()<min)
				   {min=s4.length();
				     st=s4;
				   }
				}
		  }
	}
      
      
    if(st.length()==0)
     System.out.println("No string");
   
   else
   System.out.println(st);
    
 }
 
public static boolean contain(String s1,String s2)
 {   int i;
    for(i=0;i<s2.length();i++)
      {
        String w=""+s2.charAt(i);
        if(s1.contains(w))
           continue;
           
         else
         break;
      }
     
     if(i>=s2.length())
       return true;
       
      return false;
 }

}

hi @abhishekg
you need to optimize your code it.
you worst case time complexity is o(n^3)

try to use HashMap to improve your timecomplexity.

@abhishekg
First check if length of string is less than the length of given pattern, if yes then "no such window can exist ".
Store the occurrence of characters of given pattern in a hash_pat[].
Start matching the characters of pattern with the characters of string i.e. increment count if a character matches
Check if (count == length of pattern ) this means a window is found
If such window found, try to minimize it by removing extra characters from beginning of current window.
Update min_length
Print the minimum length window.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.