Microsoft
3.6 of 5 7,033 reviews
www.microsoft.com Redmond, WA 5000+ Employees

Microsoft Software Development Engineer In Test (SDET) Interview Question

"Given a string, find whether it has any permutation of another string. Need to be efficient"
Tags: technical
Add Tags [?]
Answer Flag Question

Part of a Software Development Engineer In Test (SDET) Interview Review - one of 3,172 Microsoft Interview Reviews

Answers & Comments

0
of 0
votes
isnt it enough if we find out whether the characters in the second string is present in the first?
(also the number of times each character appears).?
- Anonymous on Feb 27, 2013 Flag Response
0
of 0
votes
The characters need to be consecutive. For example, if the second string is "abc", we need to find out whether the first string has one of the following: "abc" , "acb" , "bac" , "bca" , "cab" or "cba"
- Anonymous on Feb 27, 2013 Flag Response
This post has been removed. Please see our Community Guidelines or Terms of Service for more information.
1
of 1
vote
public boolean test(String main, String sub){
        char[] a = main.toCharArray();
        char[] b = sub.toCharArray();
        char[] c = sub.toCharArray();
        Arrays.sort(b);

        for(int i = 0; i<a.length-b.length+1; i++){
            int k=i;
            for(int j=0; j<b.length; j++){
                c[j] = a[k++];
            }
            Arrays.sort(c);
            if(Arrays.equals(b,c))
                return true;
        }
        return false;
    }
- Rachana Koneru on Mar 07, 2013 Flag Response

To comment on this question, Sign In with Facebook or Sign Up


Tags are like keywords, helping to categorise interview questions that have something in common.

Glassdoor is your free inside look at Microsoft interview questions and advice. All interview reviews are posted anonymously by Microsoft employees and interview candidates.