注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
这个面试官居然是在机场的lounge 里面给我面试的,估计是去哪儿玩了,他介绍了自己的工作,让我介绍一下自己
然后就问了一个类似1710的题目
selecting items from a menu.
You have a specific budget, and your goal is to get the maximum amount of calories that can be bought
with this budget.
Input:
A list of doubles representing the dollar prices of items (example: 1.25 for $1.25)
A list of integers representing the calories value of each item in the same order as prices.
A double representing your budget in dollar amount (example: 20.00 for $20)
Output:
An integer representing the maximum amount of calories that can be bought
without going over the budget.
比较有意思的是,我程序快写出来的时候,面试官居然喜人的给了我一组test case, 让我跑一下. 其中有一个test case
我居然就是过不了, 他是非常的得意,说不过没事,让我问一些感兴趣的问题,
public static void main(String[] args) {
Solution solution = new Solution();
List<Integer> calories;
List<Double> prices;
Double budget;
Integer max;
//can repeat same itemdget).equals(max)) {
System.out.println("Passed TEST CASE 6");
} else {
System.out.println("Failed TEST CASE 6");
}
// TEST CASE 7
calories = Arrays.asList(100);
prices = Arrays.asList(1.20);
budget = 6.00;
// maximum item inidices: 0 five times.
max = 500;
if (solution.maximumMenuCalories(calories, prices, budget).equals(max)) {
System.out.println("Passed TEST CASE 7");
} else {
System.out.println("Failed TEST CASE 7");
}
} |