Week 3
Monday
Problem
Solution
The high level algorithm is:
Find the maximum element in the array (linear, should be )
Iterate through the array to decide whether each element + extraCandies will be greater than or equal to the maximum element found in above. (linear, should be too)
The overall complexity is thus .
Tuesday
Problem
Solution
This problem is very similar to the one Prof. Halim live-coded on Lec 02. The high level algorithm is:
Use two pointers (
pt1andpt2) to mark char dealth with inword1andword2while pt1 < length of word1 and pt2 < length of word 2, build the result string alternatively
while pt1 < length of word1, append the remaining chars of word1 into res string
while pt2 < length of word2, append the remaining chars of word2 into res string
return res string
The overall time complexity is .
Wednesday
Problem
Solution
This problem is discussed during the Lec 03. Can use library sort, idea of quick sort and counting sort to solve it.
Thursday
Problem
Solution
This is a classic prefix sum problem. We use a cur variable to record the prefix sum and update the max during each iteration.
Last updated