| 2 | |
| 3 | import java.util.*; |
| 4 | class Result { |
| 5 | public static int findMinimumCharacters(String searchWord, String resultWord) { |
| 6 | // Write your code here |
| 7 | |
| 8 | int p = 0; |
| 9 | int q = 0; |
| 10 | while(p < searchWord.length()) |
| 11 | { |
| 12 | if(searchWord.charAt(p) == resultWord.charAt(q)) |
| 13 | { |
| 14 | q += 1; |
| 15 | if(q == resultWord.length()) |
| 16 | { |
| 17 | return 0; |
| 18 | } |
| 19 | } p += 1; |
| 20 | } return (resultWord.length() - q); |
| 21 | } |
| 22 | public static void main(String[] args) throws Exception |
| 23 | { |
| 24 | Scanner sc = new Scanner(System.in); |
| 25 | System.out.println("Enter Search Word"); |
| 26 | String str1 = sc.nextLine(); |
| 27 | System.out.println("Enter Result Word"); |
| 28 | String str2 = sc.nextLine(); |
| 29 | System.out.println(findMinimumCharacters(str1, str2)); |
| 30 | |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /* 2nd Approach */ |
| 35 |
nothing calls this directly
no outgoing calls
no test coverage detected