Google Interview Question

Please implement a function to generate the 3-digits numbers with no duplicate digits and no duplicate permutation. For example: 122 is not allowed and 123 321 is not allow, only output one of the permutations.

Interview Answers

Anonymous

May 8, 2015

def combination(): for i in range(1,10): for j in range(i+1, 10): for k in range(j+1, 10): print("%d%d%d" % (i,j,k)) combination()

2

Anonymous

May 11, 2015

Does your program generate 102? It doesn't consider 0s.

1

Anonymous

Jun 11, 2015

The correct answer would be: #Python def permute(): for i in range(2,10): print(1,0,i) ###***************** permute()

Anonymous

Jun 27, 2015

for i in range(1, 10): for k in range(i + 1, 10): print i, 0, k for j in range(i + 1, 10): for k in range(j + 1, 10): print i, j, k