Nov. 20, 2016
Julia worked on the algorithm in the contest, and then solved the algorithm with full score - 35.
Here is the problem statement:
https://www.hackerrank.com/contests/womens-codesprint-2/challenges/minimum-loss
Julia's C# solution:
https://gist.github.com/jianminchen/af474846d81b96f4e70fc1a5866dca15
The ideas used in the algorithm:
Sort the array with house price.
Use bucket sort similar idea to go through each bucket, compare to previous if the current is less than minimum loss or not. Each bucket keeps the two value - max/ min value.
After the contest study:
There is a solution written in C#, much simpler and smarter than Julia's C# code:
https://gist.github.com/jianminchen/c382bc1b40e47c2740a25abcaeffb846
Based on the assumption that housing price is different for each year, but I did not find the word in the problem statement.
Discussion of Time Complexity:
1. Brute force solution - O(n^2), choose any two year to compare the price. Will time-out!
2. Using Binary search - therefore, it is easy to find the minimum price, O(nlogn)
Maintain a binary search tree!
Study this C# solution using Binary search tree:
https://gist.github.com/jianminchen/c910f5d1f37309c70b489e6c75b0678c
Very classical solution using binary search tree, and very clever solution.
Memorize the solution. Warm up the solution sometimes in the future.
Compared to Java submission using TreeSet class:
https://gist.github.com/jianminchen/6fa69ef28c849d63ed0dc4b419cd0dee
3.
From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment