Amazon Interview Report
- 0of 0 votes
AnswersYou are given an unsorted integer array consisting of 1's and 0's. You need to rearrange the array with alternating groups of 0's and 1's. The group length is determined by the function f(x)
- sukheshmg February 11, 2014 in India
f(0) = 1
f(1) = 2
f(n) = [square of f(n-1) - square of f(n-2)]
if you run out of either 1's or 0's, then fill the array with whatever is left.
input: 0,0,1,0,1,1,1,0,0,1,0,0,1,1,0,0
output: 0, 1,1, 0,0,0, 1,1,1,1,1, 0,0,0,0,0
f(1) = 1
f(2) = 2
f(3) = sqr(f(2)) - sqr(f(1)) = 3
f(4) = sqr(f(3)) - sqr(f(2)) = 5
f(5) = sqr(f(4)) - sqr(f(3)) = 16
here we don't have enough 0's left to fill the last group. So, we add the five 0's that were left.| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersYou are given a n-ary tree. print all the nodes bottom up except for the right most node at each level.
1 2 3 4 a b c d e
print all except 4 (right most at level 1) and e (right most at level 2)
- sukheshmg February 11, 2014 in India| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm