Class Solution
java.lang.Object
g1701_1800.s1713_minimum_operations_to_make_a_subsequence.Solution
1713 - Minimum Operations to Make a Subsequence.<p>Hard</p>
<p>You are given an array <code>target</code> that consists of <strong>distinct</strong> integers and another integer array <code>arr</code> that <strong>can</strong> have duplicates.</p>
<p>In one operation, you can insert any integer at any position in <code>arr</code>. For example, if <code>arr = [1,4,1,2]</code>, you can add <code>3</code> in the middle and make it <code>[1,4,3,1,2]</code>. Note that you can insert the integer at the very beginning or end of the array.</p>
<p>Return <em>the <strong>minimum</strong> number of operations needed to make</em> <code>target</code> <em>a <strong>subsequence</strong> of</em> <code>arr</code><em>.</em></p>
<p>A <strong>subsequence</strong> of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements’ relative order. For example, <code>[2,7,4]</code> is a subsequence of <code>[4,2,3,7,2,1,4]</code> (the underlined elements), while <code>[2,4,2]</code> is not.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> target = [5,1,3], <code>arr</code> = [9,4,2,3,4]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> You can add 5 and 1 in such a way that makes <code>arr</code> = [5,9,4,1,2,3,4], then target will be a subsequence of <code>arr</code>.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> target = [6,4,8,1,3,2], <code>arr</code> = [4,7,6,2,3,8,6,1]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= target.length, arr.length <= 10<sup>5</sup></code></li>
<li><code>1 <= target[i], arr[i] <= 10<sup>9</sup></code></li>
<li><code>target</code> contains no duplicates.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minOperations
public int minOperations(int[] target, int[] arr)
-