| 1 | class Solution { |
| 2 | //tc N+M + Min(n,m) |
| 3 | //sc n+m |
| 4 | public boolean areSentencesSimilar(String sentence1, String sentence2) { |
| 5 | if(sentence1.length()>sentence2.length()){ |
| 6 | return areSentencesSimilar(sentence2, sentence1); |
| 7 | } |
| 8 | String smallerWords[] = sentence1.split(" "); |
| 9 | String largerWords[] = sentence2.split(" "); |
| 10 | int start=0; |
| 11 | int end1=smallerWords.length-1; |
| 12 | int end2=largerWords.length-1; |
| 13 | //find prefix words |
| 14 | while(start<=end1 && smallerWords[start].equals(largerWords[start])){ |
| 15 | start++; |
| 16 | } |
| 17 | //find suffix words |
| 18 | while(start<=end1 && smallerWords[end1].equals(largerWords[end2])){ |
| 19 | end1--; |
| 20 | end2--; |
| 21 | } |
| 22 | return (start>end1); |
| 23 | } |
| 24 | } |
nothing calls this directly
no outgoing calls
no test coverage detected