www.tobinandco.com / HQ: Charlotte
www.morgankeegan.com / HQ: New York, NY
Write code to return a sorted array of int, when passed in 2 sorted array of int to the method.
consider using only 1 loop
the efficient way would be: using a loop, pick item from array1 and array2. compare them, and add smallest into a new arrayList., followed by the higher. eventually, convert this arrayList into an int array using arrayList.toArray)int[arraylist.size()]). why adding into third array? if we pick one from first array and insert into the second array at appropriate place, it will push all subsequent elements and try to increase arrayList2's capacity. these pushing back and increasing are expensive operations. hence creating a new arrayList and adding guarantees a one time iteration.
use loop meaning 1 loop? or 1 inside of another?