I am trying to write a pseudocode function R1(key, A, B, N) that takes a non-negative integer key, and arrays A and B of length N as inputs: the function should return an index where the value key is stored in the same location in both A and B; it should return -1 if the value cannot be found in either array; and it should return -2 if there is an index j where A[i] is not equal to B[i].
I am not sure this is correct. I have tried this :
1 2 3 4 5 6 7 8 9 10
Function R1(key, A, B, N):
for 0<= i < N:
if(B[i] or A[i] == key):
return i
// Item not found in the array
return -1
if(B[i] ≠ A[i]):
return -2
end for
end function