Microsoft

  www.microsoft.com
Work in HR? Unlock Free Profile

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

Part of a Software Development Engineer In Test (SDET) Interview Review - one of 3,360 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
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
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

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.