Tiger Analytics Interview Question

Buy and sell stocks, recursion, LCM and gcd.