Introduction
It is most challenge job to prepare something last minute. I cannot push myself too hard. I just chose one of algorithms my coach selected for me, Leetcode 456, and then I enjoyed the time to hack the algorithm.
How to analyze the algorithm?
I read the algorithm and then try to figure out the best way to analyze the algorithm. I read the story about the search is out of order, s1 < s3 < s2. It just tells us that we have to think about different ways.
Best time complexity is O(n). We have to maintain maximum possible s3 value. Can you image that? I tried to analyze the brute force solution, and preprocess the array to maintain the value of each index right side maximum or minimum value. But it does not work.
We have to simplify the problem?
We like to handle s2 and s3 before s1, and also we like to keep the track of maximum s3 value. Every iteration the current visited element has to play s1 role first, see if it can play s1 < s3; otherwise, it will be considered to be candidate of maximum s3.
I am writing a novel here. Just because I spent more than two hours to try to reason the solution while I am sitting in a hotel, in a steak dinner.
Here is the discussion panel which has everything I try to put together a story here for Leetcode 456: 132 pattern.
Statistics:
Time spent: 2:30 PM - 2:50 PM
6:00 PM - 8:20 PM
No comments:
Post a Comment