fork download
  1. import java.util.*;
  2. class find {
  3. public static int findMinimumCharacters(String searchWord, String resultWord)
  4. {
  5. int p = 0;
  6. int q = 0;
  7. while(p < searchWord.length())
  8. {
  9. if(searchWord.charAt(p) == resultWord.charAt(q))
  10. {
  11. q += 1;
  12. if(q == resultWord.length())
  13. {
  14. return 0;
  15. }
  16. } p += 1;
  17. } return (resultWord.length() - q);
  18. }
  19. public static void main(String[] args) throws Exception
  20. {
  21. System.out.println(findMinimumCharacters("armaze", "amazon"));
  22. }
  23. }
  24.  
Success #stdin #stdout 0.08s 38900KB
stdin
armaze
amazon
stdout
2