Description
Solutions
Get Minimum Steps
🤘 INTERN

Given two sets of data: current and desired, each represents the order of n layers within the neural network architecture. During the training of the model, an operation can be performed to adjust the arrangement of layers. In one step, a layer is selected from the end of the list and inserted at any arbitrary position within the list.

Determine the minimum number of steps required to transform the initial arrangement (current) into the desired arrangement (desired) while training the neural network.

Note: It is guaranteed that the desired arrangement can always be achieved using the given operation.

Function Description

Complete the function getMinSteps in the editor.

getMinSteps takes the following parameter(s):

  1. int current[n]: the initial arrangement of the layers in the neural network
  2. int desired[n]: the desired arrangement of the layers in the neural network

Returns

int: the minimum number of steps required

Example 1:

Input:  current = [2, 1, 3, 5, 4], desired = [2, 4, 1, 5, 3]
Output: 2
Explanation:

Pick layer 4 and insert it in [2, 1, 3, 5] as [2, 4, 1, 3, 5].

Pick layer 5 and insert it in [2, 4, 1, 3] as [2, 4, 1, 5, 3].

Therefore, the answer is 2 steps.

Constraints:
    🦝🦝
Thumbnail 0
Testcase

Result
Case 1

input:

output: