title: How to check if a String contains a substring in any order?
body: <p>This is not same as "How to check if a string contains s specific substring?" . I found a no of questions like that here but not precisely what i am looking for.
  I am creating a program at a competitive coding site the problem of which states that we are given a string made of x,y,z and we have to count the number of substrings which contains atleast one of those chars but not all of them.I tried this...</p>
  
  <pre><code>    String text = sc.next();
        int l = text.length();
        int count=0;
       for(int j =1;j&lt;=l;j++)
        {
       for(int i1 =0;i1&lt;j;i1++){
          String g = text.substring(i1,j);
          if(g.contains("xyz")||g.contains("xzy")||g.contains("yzx")||g.contains("yxz")||g.contains("zxy")||g.contains("zyx"))
          ;
          else
          count++;
  
  
  
  
        }
  
        }
        System.out.println(count);
  </code></pre>
  
  <p>And this worked(atleast for 2 test cases). But for the larger test cases my program is violating the time limit. Now i think that is because of the number of matching conditions in the if clause. I would like to know if there is any way by which i can just check if the substring contains 'xyz' in any order instead of checking for every order.Thanks! Any help is appreciated. </p>
  
  <p>P.S- If anything else is responsible for the time limit violation, do mention out !</p>