Microsoft Software Engineer 2 - Frontend phone screen

Anonymous User
543
Jun 29, 2024
Jun 29, 2024

Had a phone screen:

Technical Question asked:

Given a sorted array of integers array is split into 2 subarray and rearraged so that back subarray moved to front and remerged.

Write a function to return the sort order of the original array in Javascript.

Example inputs (array can be split at any point into two subarray and it can be of any length):
Input :[5,1,2,3,4] // sort order of original array: ascending , [1,2,3,4,5,6]
Input :[2,1,6,5,4,3] // sort order of original array: descending , [1,2,3,4,5,6]
Input :[1,2,3,4,5,6] // sort order of original array: ascending , [1,2,3,4,5,6] array already sorted

Can anyone help in solving this problem ? (edge case : what will happen if there are 3 elements in array? [1,2,3] or [3,2,1] )

Comments (3)