Saturday, June 3, 2017

Leetcode 605: Can Place Flowers

June 3, 2017

Problem statement is here.

Julia's C# practice is here.

Why it took 48 minutes?


It is a good idea to review the process to get the correct solution, after a few submissions. Through the contest, Julia spent time to play with online judge, she submitted code more than 3 times, failed to pass the test case before submission. She failed twice with two submissions. 

Here are the code with highlights of bugs Julia spent more time she could afford in the contest. To improve her performance, she should aim to complete the easy algorithm in 10 minutes instead of 48 minutes. 



Preparation is the key


It takes a lot of discipline and hard work to be more efficient to write an easy algorithm. Julia likes to set a goal to set 10 minutes for an easy algorithm.

The idea is to go over 4 places she highlighted her mistakes in the first writing. How she introduced the bugs in her analysis.

What are missing to help her to develop the correct code?

She will study a little more and figure out what to make her coding speed up. Learn to use white boarding test, do not back and forth using online judge to correct logic thinking flaws.

Julia likes to change her style in coding. Do not rely on online judge, write a bug-free code using white boarding testing. But she should have done it early and then she starts to build up experience.

It is a good idea to set up a few test cases for the algorithm. Do not rely on the test cases behind the Leetcode online judge.

Spend at least 5 minutes in the contest to set up a few of test cases, and also calculate the answer. Use those test cases to help the design, understand the problem first.

1 0 0 0 0 1 => answer to plant flower is 1 => 1 0 1 0 0 1
0 0 0 0 1    => answer to plant flower is 2 => 1 0 1 0 1
1 0 0 0 0    => answer to plant flower is 2 => 1 0 1 0 1

1 0 0 1 0 0 0 1 => answer to plant flower is 1 => 1 0 0 1 0 1 0 1


Study the discussion



Choose the idea in the discussion - here is the link

C# code is here

Unbelievable clear and short code. It only takes 5 minutes to complete the code.

 

No comments:

Post a Comment