Amazon Interview Question for SDE1s


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

public class CheckBitPermutationInString {

    public static void main(String[] args) {
        System.out.println(isValid("11001", 2));
    }

    public static boolean isValid(String s, int k) {
        List<String> l = getAllBinarySubsets(k);
        for (String binary : l) {
            if (s.indexOf(binary) == -1) {
                return false;
            }
        }
        return true;
    }

    public static List<String> getAllBinarySubsets(int k) {
        List<String> list = new ArrayList<>();
        String format = "%0" + k + "d";

        for(int i = 0; i < Math.pow(2, k); i++) {
            list.add(String.format(format, Integer.valueOf(Integer.toBinaryString(i))));
        }
        return list;
    }
}

- guilhebl May 24, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public bool BinaryPermutation(int k, string binaryStr){
		List<string> combinations = new List<string>();
		for(int i=0;i<Math.Pow(2,k);i++){
			if(binaryStr.IndexOf(Convert.ToString(i,2).PadLeft(2,'0')) == -1)
				return false;
		}
		return true;

}

- alir2t2 June 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static bool ContainAllPermutations(string str,int k)
        {
            if (str.Count() < k * 2)
                return false;
            Dictionary<string, int> Permutation = new Dictionary<string, int>();
            for(int i=0;i<=str.Count()-k;i++)
            {
                if(!Permutation.ContainsKey(str.Substring(i,k)))
                {
                    Permutation.Add(str.Substring(i, k), 1);
                }
            }
            if(Permutation.Count== Math.Pow(2, k))
            {
                return true;
            }
            return false;
        }

- Idan October 26, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

O(n) solution, uses O(2**k) memory.

def foo(s, k):
    if len(s) < k + 2**k - 1:
        return False
    (count, v) = (2**k-1, [0]*2**k)
    q = reduce(lambda a,b:2*a+b, s[:k], 0)
    v[q] = 1
    z = 2**(k-1)
    for si in xrange(len(s)-k):
        q = (q-s[si]*z)*2+s[si+k]
        if v[q] == 0:
            v[q] = 1
            count -= 1
            if count == 0:
                return True
    return False

print foo([1, 0, 0, 1, 1], 2)

- adr June 11, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More