Monday, April 18, 2016

K index - Algorithm (II) using Queue

April 18, 2016

More code writing. Try to use Queue to solve the problem. Write more than one solution using Queue.

Julia practiced twice, first one hour she failed some test cases using HackerRank. And then, she tried again.

Practice #2:
https://gist.github.com/jianminchen/ce7ccfa5db5b57c36d6742b622e9153e

First blog about this algorithm - K index:

http://juliachencoding.blogspot.ca/2016/04/k-index-algorithm.html

Julia wrote C# implementation using Queue,
https://gist.github.com/jianminchen/63c0bccec2ab476d71abbe43c8837566

Test cases:
1. Input
4
1     2   3     4
5     6   7     8
9   10 11   12
10 14 15   16
2
Yes, 10 is found at arr[3,0], 2 steps away from arr[2,1]


Time spent:
More than 30 minutes

Learned from mistakes:
1. Two dimension array arr[,], use getLength(0) and getLength(1) for first and second dimension length; But, jagged array - arr[][], getLength(1) will throw exception, use arr.Length, arrp[0].Length to check the size.
 
The first practice using queue, Julia created a run-time exception - index out of range; the error is so late to catch, not in compile time. So, take it seriously. Array, two dimensional array, jagged array are very basics.

https://gist.github.com/jianminchen/93f963043c47649a496a2fccc862d801

change search array to use two dimensional array:
https://gist.github.com/jianminchen/9346c2d2cb2e611ec2db3519dc7a879a

Read blog:
http://stackoverflow.com/questions/597720/what-are-the-differences-between-a-multidimensional-array-and-an-array-of-arrays
http://stackoverflow.com/questions/12567329/multidimensional-array-vs?lq=1

https://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx

April 21, 2016
Julia found something she likes - C# tutorial
read it every day when you have 20 minutes in the morning.

https://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx

No comments:

Post a Comment