Thursday, April 18, 2019

Leetcode 402: remove K digits - Brute force solution

April 18, 2019

Introduction


It is so painful since I could not pass all test cases after more than 40 minutes in second mock interview. It is a medium level algorithm. I will fix the bug and also analyze my solution written in mock interview.


Code study

I spent 40 minutes in mock interview but I only passed one test case. Afterwards, I spent almost one hour to play all test cases and then make it work.

It is a brute force solution. Somehow my nature to find a solution and also write a solution does not produce good fruit. I like to make it work and then compare to the solution using Stack, I learn the huge difference in terms of ease to write and efficient of time complexity.

I am not the material of stack thinking yet. I will be one day. I just need to practice daily, and make it like lunch or dinner activity.



Naive solution 

I came out the naive solution first, and without searching for optimal linear solution, I started to write code.

It is such great learning experience to practice the algorithm in mock interview. I have 60 minutes, this was the second algorithm, and I came out the idea to find minimum number using O(N * N) algorithm. Without searching for optimal solution, I decided to write the code to implement the idea.

No comments:

Post a Comment