Two questions were asked, on codility platform. 80 mins were given.
Given hisorical data of transaction of last N days, calculate the maximum profit on buying and selling the assets. If any assest is sell then we can buy new one, and if one is bought then we can sell the other one.
example test case:
[4,1,2,3]
sell 4, buy 1, sell 3 maxProfit=4-1+3=6
[1,2,3,3,2,1,5]
sell 3,buy 1,sell 5
maxProfit=3-1+5=2
Distribute P monitors in different distance, given d[k] is the distance array with number of monitors to be delievered at that distance as C[k]. The order of distribution is such that first the monitors will be distributed at the near stores and then move to the farther distances. we need to find the number of distance the monitors are delievered.
Example test case-
D- [5,11,1,3]
C-[6,1,3,2]
P=7
3 monitors delievered at distance 1 and 2 monitors at distance 3 so the ans is 2
TestCase 2-
D-[10,15,1]
C-[10,1,2]
P=3
o/p: 1
2 monitors at 1 distance