Showing posts with label array construction. Show all posts
Showing posts with label array construction. Show all posts

Monday, February 20, 2017

Hackerrank university code sprint #2 - Bronze medal

Feb. 20, 2017

Julia was so happy to know that she got a bronze medal for her most favorite codesprint - university codesprint. She scored 50, spent more than 15 hours, compared to highest rank scoring 100%, score 430, in less than 3 hours, she has a long way to go. But she knew that how hard she has to work on, to make that extra 30 points, her last university codesprint was 20 points, because she spent over 10 hours to work on hard algorithm array construction, ended up scoring 0 on the algorithm.

The university codesprint is by far most challenge codesprint one.

She did look up ranking in Canada, and tried to learn through leaderboard, she ranks at 38, and also she found a good article to read from Bai Li, ranking , score 179.80, 245/6591.

Read his blog about competition programming to talk about rankings.

Study other players, and try to figure out how they got so advanced skills in competitive programming. 


Bai Li - HackerRank
How to succeed in your intern?
Erick Lin - How does an undergraduate do?

Hieu Le

Corey Chen

Marek Cygan
Abu Naser Bikas

competitive programming blog

Sunday, December 25, 2016

HackerRank - university code sprint - Array construction - code review

Dec. 25, 2016

Introduction
A few of facts about the algorithm:
1. In contest, spent over 10 hours to work on
2. The algorithm is advanced one
3. Score 8 out of 80
4. The algorithm is really a challenging one
5. Spent over 10 hours to work on after the contest, studied C# code


http://juliachencoding.blogspot.ca/search/label/array%20construction%20%28series%201%20of%205%29

Workout 

1. Plan to write a code review request on stackexchange.com.
2. Need to study how to post a good code review on stackexchange.com
3. Be careful that do not get down vote, off-topic
4. Put down ideas why to ask code review
5. Julia also learned through the code review, how to write better English, her grammar mistakes.


Code Review Link

Case study:
http://meta.codereview.stackexchange.com/a/1035/123986

http://meta.codereview.stackexchange.com/users/11974/user1131146-account-abandoned


Sunday, December 11, 2016

Array Construction - Code Review

Dec. 11, 2016

Introduction

Array construction is the first advanced algorithm Julia tried to work on in the contest, she did try to work on over 10 hours, but she scored 0 (maximum score 80). Through the contest, she started to understand the algorithm and built up strong interest in problem solving.

Later, she read one of solution, and then, spent over 4 hours to understand the pruning idea to avoid timeout issue.

Later, she did very intensive research on recursive function. But, she needs to get it on stackexchange.com, share her interest and questions, and then, see if she will get any surprise. Success after team work, Julia likes to practice the belief.

Previous blogs about the algorithm:
Labels: Array Construction (Series 1 of 5)

http://juliachencoding.blogspot.ca/2016/11/hackerrank-codesprint-array.html

Workout:

Plan to post a question on stackoverflow.com code review for code review.


Sunday, November 13, 2016

HackerRank - University CodeSprint - Array Construction - In contest performance (series 1 of 5)

Nov. 13, 2016

Problem statement:
https://www.hackerrank.com/contests/university-codesprint/challenges/array-construction/submissions/code/7825209

Advanced algorithm, Max Score: 80

Over 6 hours to work on the algorithm.

Warm up the topic:
It felt so good to work on the algorithm.

First, Julia warmed up the backtracking algorithm using sample test case, spent more than one hour.
input:
1
3 3 4
output:
0 1 2
Here is the submission: pass the above test case, score 0.
https://gist.github.com/jianminchen/c17ce782080a99a2480ff1c6eb390628

There are a lot of issues, timeout, wrong answer. As long as the solution used the backtracking, DFS with some pruning, the timeout issue could not be avoided. Julia worked up to 3:30am, more than 10 hours, 5 hours before the end of contest. She finally gave up the effort and called it a day.

Julia felt so challenged through the problem solving, she went through backtracking, timeout issue, and then, she did some pruning, set up maximum/ minimum range for the search, through sum of array and sum of difference of any two elements. She did some research after over 10 hours, and then, find the article to reduce O(n^2) to O(n) to calculate sum of (Ai-Aj) for any i, j from 1 to n.

Highlights of great things in the contest: (need to fill out with really good things, think hard again.)
1. First, Julia did search from smallest word to biggest one.
This way, if she finds one word, the word should be the smallest one. Backtracking algorithm she did practice on phone number.

2. Julia had backtracking code experience, on Leetcode phone number.

3. Although Julia did not know DFS/backtracking could not solve the timeout issue, she knew that backtracking practice helps her to understand the problem, really understand the scalability issue. She understands the depth of the problem, and also understand the math analysis of time complexity is such important to help design.

4.
5.
6.

Highlights of things to work on:
1. Backtracking algorithm cannot beat the dynamic programming algorithm on timeout issue.
DP solution can give the math formula about time complexity analysis, and then, further pruning gives out better performance.

10 hours hard word, learn the first lesson.

2.
3.
4.
5.
6.


Last submission: score 8 of 80
Julia spent over 20 minutes to clean up the code, reduce the complexity of the code through so many efforts, hours work. Just use common sense, "The real challenge is from mathematics! What is time complexity of my algorithm? I had to depend on those pruning ideas - it worked great on my test case, up to 50 (size of array)(line 101 - 119), only take around 110 milliseconds, but it still failed on timeout issue."

https://gist.github.com/jianminchen/42300e1f09b748d5a165990f0c7f64b2

Study C# submissions:

1. perfect solution with full score 80

https://gist.github.com/jianminchen/49f45acc69b4d87c51d02c81a788fbc9

2. perfect solution with full score 80

https://gist.github.com/jianminchen/096ebc5bc1769b83b38ec6eeaabbc7c5

3. score half score 40

https://gist.github.com/jianminchen/f85de0c2b6014ff79d1097ce12705691

Constructive algorithm: (preprocessing, and then, lookup)
(HackerRank - array construction is a constructive algo.)
https://www.quora.com/What-does-the-constructive-algorithms-tag-mean-at-Codeforces