MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

PermutationInString.java:2–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1//two map comparision
2class Solution {
3 public boolean checkInclusion(String s1, String s2) {
4 int n = s1.length();
5 int m = s2.length();
6 if(m<n) return false;
7 int map1[] = new int[26]; //0
8
9 for(int i=0;i<n;i++){
10 map1[s1.charAt(i) - 'a']++;
11 }
12 for(int i=0;i<=m-n;i++){
13 int map2[] = new int[26];
14 for(int j=0;j<n;j++){
15 map2[s2.charAt(i+j) - 'a']++;
16 }
17 if(isMatched(map1,map2)){
18 return true;
19 }
20 }
21 return false;
22 }
23 private boolean isMatched(int map1[], int map2[]){
24 for(int i=0;i<26;i++){
25 if(map1[i]!=map2[i]) return false;
26 }
27 return true;
28 }
29}
30
31
32// Sliding Window

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected