-2

I have an array arr1={4,5,8,9,2,1} and a second arr2 = {6,5,8,2,4,5,7,1} and i wan to remove sequence of two value from arr1 if they occur in arr2 ;and append the result in arr2. like "4,5" in arr1 ; after removing it will bearr1={8,9,2,1} so arr2 ={6,5,8,2,4,5,7,1,8,9,2,1}

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Med Bkb
  • 1
  • 2

1 Answers1

-1

This is duplicated, please check similar questions, for example:

Java Remove Duplicates from an Array?

Anyways,if you can't use Set the not that efficient way to do it is by simply having a pointer which you use to iterate through the array. If you find the first int of the two introduced (in this case, number 4) you got to check the next one. If both are the same (4,5), you erase them (put a NULL on it for example) and continue iterating from the next position after the 5. Then, when you finished iterating simply create a new array with the length being the number of positions in both arrays different than NULL and append them on this result array.

Román
  • 136
  • 1
  • 9