Skip to content

Practice Longest Unequal Adjacent Groups Subsequence II

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

Medium#2901
LeetCode Problem

Longest Unequal Adjacent Groups Subsequence II

Problem Statement

Choose a longest sequence of increasing indices from words. For every adjacent pair of chosen indices, their groups values must differ, their words must have equal lengths, and those two words must differ at exactly one character position. Return the selected words in index order. Any longest valid answer is acceptable. The input words may have different lengths.

Source: Longest Unequal Adjacent Groups Subsequence II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
words = ["bab","dab","cab"], groups = [1,2,2]
Output
["bab","cab"]

# Example 2

Input
words = ["a","b","c","d"], groups = [1,2,3,4]
Output
["a","b","c","d"]

Constraints

1 <= n == words.length == groups.length <= 1000
1 <= words[i].length <= 10
1 <= groups[i] <= n
words consists of distinct strings.
words[i] consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Longest Unequal Adjacent Groups Subsequence II.

Review your practice with PhantomCodeAI

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