Company: Nutanix

Difficulty: hard

Problem Statement

Minimum-Cost Interleaving with Separators You are given two integer sequences A and B . Interleave all their elements into one sequence while preserving the relative order within A and within B . The ordinary cost between two adjacent elements is their absolute difference. You may place at most K separators between adjacent elements. A separator makes the cost across that boundary zero. Find the minimum possible total cost. Input Format The first line contains three integers N , M , and K . The second line contains N space-separated integers describing A . The third line contains M space-separated integers describing B . Output Format Print the minimum possible total cost. Constraints 1 <= N, M <= 80 0 <= K <= N + M - 1 -10^9 <= A[i], B[i] <= 10^9 The answer and intermediate costs require signed 64-bit integers. Example Input: 2 2 1 1 4 2 7 Output: 3 One optimal interleaving is 1 2 4 | 7 . Its cost is |1-2| + |2-4| + 0 = 3 . Notes Separators may only be placed between

More Nutanix OA questionsInterview experiences