字節跳動筆試題 2020.6.20

1.NodeList:a Nodelist A is input,hope Ur code could output a NodeList B constructed by the reversed neighbour Nodes in Nodelist A。
input:1>2>3>4>5>6
output: 2>1>4>3>6>5

2.Find The Only Number。An array[int] A is input, and the element in A is repeated twice (except the ONLY number),hope U find the ONLY number.
input:1 1 2 2 3 3 4
output:4
PS:Seems easy,actually it is easy in Hash.

3.Give Charge。coins[c1,c2,c3,c4…] and charge are input,find the minimum number of coins with a sum equaling to charge. If not exist, return -1.
input [1,2] 2
output 1

4.Glob Path Algorithm.

5.A 2d Array[int] A is input,Find a pair of (x1,y1), let the line of x=x1 and the line of y=y1 completely cover the points in A, with the minimum (1000x1+y1).If not exist, return (-1,-1).
input [[1,1][2,2]]
output (1,2)

6.Assuming U and Papa are very very borded in home,and there is a box and some balls, papa wanna play a game with U. The rule is, at begining there is some balls in the box, and the number of balls is N, if N is even, then papa will take away 0.5*N balls, if N is odd, the U could add one ball into box. The question is, how many turns will U and papa paly until the number of remained balls is 1?(taking away is 1 turn, adding ball is 1 turn)
input: 2
output:1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章