as far as i can think, stopping condition whould be
if (index of 3rd array is equal to the sum of the first two array)
return final_array;

if i get the code, will upload it....