HBY
BAN USER- 0of 0 votes
AnswersGiven a array of integer and group size, reverse array by group size, example as follows:
- HBY in United States
[1, 2, 3, 4, 5, 6], 1 -> [1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6], 2 -> [2, 1, 4, 3, 6, 5]
[1, 2, 3, 4, 5, 6], 3 -> [3, 2, 1, 6, 5, 4]
[1, 2, 3, 4, 5, 6, 7, 8], 3 -> [3, 2, 1, 6, 5, 4, 8, 7]
Design test cases for you API| Report Duplicate | Flag | PURGE
Salesforce SDET Algorithm - 1of 1 vote
Answersyou have a interface called Op and a Filter interface
- HBY in United States
interface Op<T> {
public boolean hasNext();
public boolean<T> next();
}
interface Filter<T1, T2> {
public boolean filter(T1 t1, T2 t2);
}
design a MutualOp that has below API, MutualOp should return the ops that combine op1 and op2, also should meet with the filter
class MutualOp implements Op{
public MutualOp(Op left, Op right, Filter<Op, Op> filter) {
this.left = left;
this.right = right;
this.filter = filter;
}
public boolean hasNext {
......
}
public T next {
......
}
}| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
Answerscalculate minimum h-index for a sorted integer array(http://en.wikipedia.org/wiki/H-index)
- HBY in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 1 vote
AnswersAssuming you're playing one game that you need guess a word from a dictionary. You're given a machine you can try to guess the word, the machine will return how many characters has been matched by your guess. Design a system to crack the word.
- HBY in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 1 vote
AnswersPermutate a list of string
- HBY in United States
this question is supposed permutate the characters instead of who string,
as input example {"red", "fox", "super" }, the expected output is
rfs
rfu
rfp
rfe
rfr
ros
rou
rop
roe
ror
rxs
rxu
rxp
rxe
rxr
efs
efu
efp
efe
efr
eos
eou
eop
eoe
eor
exs
exu
exp
exe
exr
dfs
dfu
dfp
dfe
dfr
dos
dou
dop
doe
dor
dxs
dxu
dxp
dxe
dxr| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 1of 1 vote
AnswersA 2D array filled with integer, define a flow from one point to its neighbor only if the value of current point is not less than its neighbor's value. Consider up edge and left edge as east coast, bottom edge and right edge as west coast, find all position that it can flow to east coast and west cost both
- HBY in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm
Sorry I didn't make this question clear, this question is supposed permutate the characters instead of who string, as input {"red", "fox", "super" }, the expected output is
rfs
rfu
rfp
rfe
rfr
ros
rou
rop
roe
ror
rxs
rxu
rxp
rxe
rxr
efs
efu
efp
efe
efr
eos
eou
eop
eoe
eor
exs
exu
exp
exe
exr
dfs
dfu
dfp
dfe
dfr
dos
dou
dop
doe
dor
dxs
dxu
dxp
dxe
dxr
My python code
- HBY December 31, 2015def groupReverse(list, size):
if size == 1: return list
n = len(list) / size
for i in range(n + 1):
list = list[:i * size] + list[i*size:(i+1)*size][::-1] + list[(i+1)*size:]
return list
print groupReverse([1,2,3,4,5,6], 1)
print groupReverse([1,2,3,4,5,6], 2)
print groupReverse([1,2,3,4,5,6], 3)
print groupReverse([1,2,3,4,5,6,7,8], 3)