githubEdit

Week 3

Monday

Problem

Solution

The high level algorithm is:

  1. Find the maximum element in the array (linear, should be O(n)O(n))

  2. 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 O(n)O(n) too)

The overall complexity is thus O(n)O(n).

circle-info

Here I am lame so just sort the list first LOL.

Tuesday

Problem

Solution

This problem is very similar to the one Prof. Halim live-coded on Lec 02. The high level algorithm is:

  1. Use two pointers (pt1 and pt2) to mark char dealth with in word1 and word2

  2. while pt1 < length of word1 and pt2 < length of word 2, build the result string alternatively

  3. while pt1 < length of word1, append the remaining chars of word1 into res string

  4. while pt2 < length of word2, append the remaining chars of word2 into res string

  5. return res string

The overall time complexity is O(m+n)O(m+n).

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