Skip to content

Practice Uncrossed Lines

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1035
LeetCode Problem

Uncrossed Lines

Problem Statement

Place nums1 and nums2 on separate horizontal lines in their original order. Connect equal values across the two lines, using each array element at most once. Connections may not cross or share endpoints. Return the largest number of connections possible.

Source: Uncrossed Lines on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums1 = [1,4,2], nums2 = [1,2,4]
Output
2

# Example 2

Input
nums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2]
Output
3

# Example 3

Input
nums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1]
Output
2

Constraints

1 <= nums1.length, nums2.length <= 500
1 <= nums1[i], nums2[j] <= 2000

Related LeetCode Problems

Practice more problems similar to Uncrossed Lines.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.