[Flax club trick OA] TruckSpace

 

 

 

1. TruckSpace (2 sum): given a set of numerals and availableTruckSpace packageSpaces, required to take two packages add up to availableTruckSpace - 30, return to their index. If there are several packages to meet the conditions set, came back to the group containing the largest package.

Tips: beginning with hashmap do not have a case too, later found there may packageSpaces duplicate numbers, packages such as to meet the conditions of the two groups are contained in the largest package. I later changed it to first find the group have the greatest package on the direct return, the last case before.

 

2 The test questions are old questions, the first one is truckSpace, give you a List <Integer> packageSize, and then give you a truckSpace, you need to select from this list two distinct number which, added together the value of to equal (exactly) truckSpace -30. I have to say about this place, because I was finishing someone else's problem, I see is said to be less than or equal truckSpace -30, but my question is number two add up to exactly equal truckSpace -30. The return value is a list in which two number index, and if there are two or more Result, that returns the maximum packageSize.

 

1. Get the total capacity is equal to two cargo truck total capacity by 30

 

Guess you like

Origin www.cnblogs.com/liuliu5151/p/11026146.html