Saturday, March 12, 2016

HackerRank - strings - GemStones

March 12, 2016
GemStones:
Problem statement:
https://www.hackerrank.com/challenges/gem-stones

First practice:
Julia's C# solution:
https://gist.github.com/jianminchen/aa85318f91fbcdc8f74d

More practices:

Julia, you do not need to use jagged array to store all the string, you can use one array, and then, keep adding to the array the count.

So good to learn from other submission - Julia likes HackerRank, quickly get updated with more ideas/ implementation / more informed.

1. Improvement 1:
Here is other person's implementation - less space, beat your solution! 
https://gist.github.com/jianminchen/cb0886705d99423a321f

So, Julia, write another one - short one - 
not: int[][] countA = new int[len][];

     int[]   sumA = new int[26]; 
space improvement, code is much short. 

Julia wrote second implementation using one dimension int[26] instead of int[len][]
https://gist.github.com/jianminchen/10ece1c63d85e6ae3e12

2. Improvement 2:
Here is one of solution using bit manipulation - Great idea - try to use it as well!
Java
https://gist.github.com/jianminchen/c3d56eedcb794b0fa496

Julia uses C# to implement the bit manipulation:
https://gist.github.com/jianminchen/aba5bad049353738a520

one comment on line 39:
int x = -1; // julia, debug the code, and learn the idea to use bit manipulation 

why x = -1?
recall -1 is FFFF in bit expression; since 1+1 = 0, so
FFFF
       1
---------
0000

3 solutions - space complexity using jagged array to one dimension array to one integer.

Nov. 30, 2016
Review stackexchange code review post:
http://codereview.stackexchange.com/questions/61248/diamond-in-the-rough-finding-gems-in-the-rocks


No comments:

Post a Comment