## Amazon Interview Question for SDE1s

• 1
of 1 vote

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++) {
}
return list;
}
}``````

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++){
return false;
}
return true;``````

}

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)))
{
}
}
if(Permutation.Count== Math.Pow(2, k))
{
return true;
}
return false;
}``````

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)``````

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.

### 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.