The first way you did it, each point has 4 other points that are either left, right, above or below it. You don't distinguish the direction, you just count them up and get 4. Because all 9 have this condition, you increment k for each point.
Your second method distinguishes between left, right, above and below. Because of this, only 1 point meets the criteria.
I don't see a real difference between both methods
What I don't understand is how you came up with the second method and not understand why it's different from the first. When you got the correct result, did you even evaluate what you had done. Did you step through your input file (or the samples from the linked web page) to see how they would be processed by your code? That's what a good programmer needs to learn to do. Step through your code and see how the variables change. When they change in an unexpected way, you need to revise your code.
Here is the link to the question if you want to know what that input is although its not necessary:
And no, the link you gave is very necessary. Without it I had no idea what you were trying to do.
Thanks for the reply doug, i was kind of lazy to trace it maybe lol cause I had other things so I thought asking here is a good idea :P but mb. thanks though!