How to Solve this??
Anonymous User
263

Given an Array A, partition it into two (contiguous) subarrays left and right such that

  1. Every element in left is less than or equal to every element in right
  2. left has the smallest possible size
  3. left & right are non-empty as its guaranteed such a partition exists.
    Return the length of left after such partition.
Eg-1:
Input=[5,0,4,6,3,8] , Output: 5

Since if you partition @ 3 (index=4) all elements in left will be less than right and cannot shrink left further satisfying the three conditions

Eg-2:
Input=[5,0,4,6,8] , Output: 3

left Partition @ 4 (Index=2) which is smallest left satisfying the above conditions.
I couldn't come up with a solution in a 45 m in interview for this problem. Thinking totally bombed it... :(

Comments (2)