employer cover photo
employer logo
employer logo

Cadence Design Systems

Engaged Employer

Cadence Design Systems Interview Question

You have two integer arrays and you should sort them into one array.

Interview Answer

Anonymous

Nov 1, 2023

I just declared a new array whose length is equal to the sum of the two given array lengths. went through the two arrays using a single loop. I declared index pointer 1 for the first array and index pointer 2 for the second. Then I compared if the first pointer's corresponding value was greater than the second pointer's value. then add the second pointer's value to the new array. if the first pointer's corresponding value was less than the second pointer's value. then add the second pointer's value to the new array. if the two values are equal the add them to the new array. The breaking point is when one of the first pointers and the second pointers are out of the index and then go out form the loop. And finally, wrote two loops one for the first array and the other for the second array to make sure that the remaining values are added to the new arrays.