Showing posts with label 6 hours work on one algorithm. Show all posts
Showing posts with label 6 hours work on one algorithm. Show all posts

Tuesday, May 15, 2018

Do I make things too easy?

May 15, 2018

Introduction


It is so much laughing today since I had chance to review my own code written more than 12 months ago. Is that true every 12 months you advance your programming skills? Since I learn how to come out dynamic programming solution without any headache, I found out my practice over 6 hours in the contest was so such a good thing to laugh about.

I am self-learner on algorithm problem solving. I am pushing myself to top of world level? I could not believe that I wrote so many lines of code, I documented it. The blog serves the purpose to teach me that good code is to write short, very clean code compared to the long complicated functions.

Code comparison


Here is the solution I played with stack with so many things, including extra comment up to 400 lines of code. I did it more than 13 months ago.

Laughing moment. Laughing...

I wrote simple code today. So simple and I could not laugh one more time. The code still has bugs, but I will sort out the constraints in the problem statement.

Dynamic programming solution is here written on May 15, 2018.

Keep writing some code every day and write some coding blog every day.



Sunday, April 23, 2017

Manhattan 2 - booking woman in tech

April 23, 2017

Introduction


It is most favorite algorithm in the contest. The algorithm is to find the optimal solution using DFS/ BFS, and also need to work on memorization to remove duplicate work, take care of timeout issue.

The problem statement is here.

Julia spent so many hours to work on DFS - recursive function, or using  a stack to do the work. Search the blog using DFS and then a lot of work will be listed here. But Julia worked on in the contest more than 6 hours from 2 pm to 8pm, and she still could not figure out 5 wrong answer test cases.

Algorithm problem solving is such a fun activities. Through those long hours problem solving, Julia now knew so many things she had to learn and work on. This booking contest just let her know that how challenge the work will be if she lands  a job to deal with millions customer.

Code review


The last submission in the contest scored 30 out of maximum score 50. The code is here.

5 runtime error, not timeout.

The submission scored 25 out of maximum score 50, timeout 5 test cases at least. The code is here.

The submission score 23.75, timeout and runtime error. The code is here.

This is the great workout for Julia to learn the algorithm. She replaced recursive solution with a stack, and then she worked on the idea to avoid duplicated calculation. Every node is visited and then sum and maximum value will be recorded, only better candidate can allow to visit again.

From the score 23.75 to 30, Julia worked on the problem solving, understood how important to keep the code as simple as possible. She worked on her last submission to clean up code more than 30 minutes. She learned to discipline herself to show clean and readable code.

Actionable Item


4/26/2017 9:32pm

Work on the test case 9, and then figure out why it is a wrong answer for my submission. Look into the issue. Figure out the solution to pass all test cases first.

Post a code review once I can write a solution to pass all the test cases. Right now, there are 78 players scoring full score 50 in the contest.

Similar question "KnightL on a chessboard" was asked before, the link is here. The code review is so great and Julia applied the tips from code review through the contest.

4/28/2017
After studying the test cases, Julia found one counter example of her assumption - her design flaw:
matrix
1 1 1 1 1 1 1
1 1 6 7 8
1 6 1 1 1
1 6
1 6
1 6
1 6 6 6 6 6 6
seconds is bigger than 14, for example 20 seconds, we need to count 6, 7, 8 for biggest path 1 1 6 6 6 6 6 6 6 6 6 6, extra 5 seconds will take a visit nodes 6 -> 7 ->8 and back to 6.

Follow up 


May 14, 2018
I reviewed the performance of the algorithm in the contest. I did spend over six hours, and submitted over 20 times to try to get more points. And I read the last submission with a few functions, in total there are more than one hundred lines of code. It is too complicated and not practical approach from my point of view.

I believe that the dynamic programming solution can be found and should be easy and clean code. I like to plan to work on this algorithm again, and test how good I can be compared to more than 12 months ago.

Here is my C# algorithm written using dynamic programming.