I have two arrays of equal length that I am comparing. They are both in ascending order. I would like to compare the two array and find when array1 is greater than array2, then at that point make a third array that returns a '1' at that instance. once this has happened i would like array1 to take to value of the index where that instance is and array2 to continue searching from that instance until it finds the next value that is greater and so on. for example:
Array 1: [ 1 2 4 5 8 9 11]
Array 2: [1 2 3 4 5 6 7 ]
Array 3: [0 1 1 0 1 0 0 ]
index one of array1 is not less than index one of array2 so array 3 returns 0
index one of array1 is kept
index one of array one is less than index two of array2 so array3 returns 1
index two of array1 is now taken
index two of array1 is less than index three of array2 so array3 returns 1
index three of array1 is now taken
index three of array1 is not less than index four of array2 so array3 returns a 0
index three of array1 is kept
and so on….
so array1 keeps its value until the condition is met and then it takes the value of the index at which the condition is met and array2 continues one index at a time regardless looking for a value at which the array1 index is met.
Best Answer