注册一个facebook采访问题

时间:2014-02-11 11:05:23

标签: python algorithm python-2.7

http://learn.hackerearth.com/question/400/facebook-programming-challenge-bar-problem-n-friends-are-playing-a-game/#c3089

对于上述网址中的问题,我做了一个示例程序,其中给出了示例输入,并从上面提到的那个中获得了不同的解决方案。 {4,5,6,7,8,9}。 这种蛮力方法有什么问题?我只是想纠正我对给定问题的理解。

a=[2,5,3]
b=[8,1,6]
c=[7,4,9]
outList=[]
for i in a:
    for j in b:
        for k in c:
            outList.append(sorted([i,j,k])[0])
            print i,j,k,sorted([i,j,k])[0]
print "List of numbers"
print sorted(set(outList))

Output
------
2 8 7 2
2 8 4 2
2 8 9 2
2 1 7 1
2 1 4 1
2 1 9 1
2 6 7 2
2 6 4 2
2 6 9 2
5 8 7 5
5 8 4 4
5 8 9 5
5 1 7 1
5 1 4 1
5 1 9 1
5 6 7 5
5 6 4 4
5 6 9 5
3 8 7 3
3 8 4 3
3 8 9 3
3 1 7 1
3 1 4 1
3 1 9 1
3 6 7 3
3 6 4 3
3 6 9 3
List of numbers
[1, 2, 3, 4, 5]

1 个答案:

答案 0 :(得分:1)

链接问题中的问题描述是错误的。它说“第三大”,但这个例子使用“第三小”。

你的解决方案似乎很好。