April 10, 2016
Problem statement:
https://www.hackerrank.com/challenges/string-function-calculation
Time spent: 2:40pm - 3:35pm 20 minutes to think, 20 minutes to write down in C#
Understand the problem, so, here are her thoughts:
Brute force solution:
pass one test case: aaaaaa, return 12,
failed test case:
abcabcddd,
wrong answer - Easy fix, index error on the loop
score 8.89/ 80
one test case: wrong answer
All other test cases time out
https://gist.github.com/jianminchen/09c77ba32b156f765b4debb2bccba0c8
Need to work on KMP, or Boyer-Moore algorithm, see how to make HackerRank happy, score more points.
http://www.cs.tufts.edu/comp/150GEN/classpages/BoyerMoore.html
blog:
http://juliachencoding.blogspot.ca/search/label/string%20functions%20review
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)
ReplyDeletefunction stringFunctionCalculation(t){
var allPairs = {};
for(var i=0 ; i<t.length ; i++){
for(var j=0 ; j<t.length-i ; j++){
if(allPairs[t.substr(j,i+1)]){
++allPairs[t.substr(j,i+1)];
}
else{
allPairs[t.substr(j,i+1)] = 1;
}
}
}
var max = -1;
for(i in allPairs){
var res = i.length*allPairs[i];
if(max<res){
max = res;
}
}
console.log(max);
}
// only work for those string whose length is less.