Ah! So z is a function of x, y, and k.
That looks almost correct. What part were you unsure about?
The notation max2(x, y) is not standard, in my experience; I would guess it means [max(x,y)]2. But in your algorithm, you appear to be treating it as max(x2,y2), which not the same (unless x and y are known to be positive). There is also another small error in your second case.
Did you copy the problem itself exactly as given to you? Were you given a definition of the notation?