is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
The DP problem seems to be the best solution. I tried it on my own and found another way, but it's not optimal. However, still wanted to post it here.
- tandemfelix March 30, 2015Say we have stock prices s = 3 4 1 2 3 5 1
s[2] = 1
Now we can use a sorted map with s[i] as key and i as value.
Now we create two pointers a and b. a starts from the front of the sorted map and b starts from the end.
We move a forward and b backward and at each step check if map[a] < map[b] i.e. does a occur before b in the stock prices. As soon as this condition is true, we've found our first pair of prices a, b which gives us maximum profit. If we are allowed k transactions we simply keep moving a and b towards each other until we have satisfied map[a] < map[b] k/2 times (k transactions: k/2 buys and k/2 sells).
What do you guys think?