QuickenLoans OA

应该是网上海投了简历, 收到了HR的电话,半个小 时寒暄之后,说要发一个Hackerrank 的OA来做做看。
预留时间是三个小时, 我硬是拖到了第二周才把OA做了。
一共两道题,题目不难。
第一道是 : 利口二石。
第二道是 : 是一个 coursera 的 Online assessment。

Min discount problem -
给你的 singature 是这样的 public static void finalPrice(List prices)
Output 是打印两行数字。 第一行表示finalPrice 总价, 第二行表示 items index that will not get any discount.
举例说明 prices array : [5, 1, 3, 4, 6, 2]
The discount on the price is the first equal to or lowest element on the right side of current price.
For example -
5 - 1 = 4
1 - 0 = 1 (右侧没有比他小的price 了,因此没有折扣)
3 - 2 = 1
4 - 2 = 2
6 - 2 = 4
2 - 0 = 2 (右侧没有比他小的price 了,因此没有折扣)
totalPrice = 4 + 1 + 1 + 2 + 4 + 2 = 14
Output -
14
1, 5