Google Interview Question
1,223 Interview Reviews |
Back to all Google Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Graduate Software Engineer at Google:
Given a string, find the minimum window containing a given set of characters.
See more for this Google Graduate Software Engineer Interview
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (2)
public static int minWindow(char[] str, char[] chars, int startIndx, int i, int j) {
if (j == chars.length) {
// found the solution
// check the minimum
if ((i - startIndx) < minWin)
minWin = i - startIndx;
return minWin;
} else {
for (int k = i; k < str.length; k++) {
if (str[k] == chars[j]) {
if (j == 0){
startIndx = k;
}
minWindow(str, chars, startIndx, ++k, ++j);
}
}
}
if (minWin > 0) {
return minWin;
}
return -1;
}
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
0 of 0 people found this helpful
by Naresh:
if (j == chars.length) {
// found the solution
// check the minimum
if ((i - startIndx) < minWin)
minWin = i - startIndx;
return minWin;
} else {
for (int k = i; k < str.length; k++) {
if (str[k] == chars[j]) {
if (j == 0)
startIndx = k;
minWindow(str, chars, startIndx, k++, j++);
}
}
}
if (minWin > 0) {
return minWin;
}
return -1;
}