Skip to content

Practice Longest Unequal Adjacent Groups Subsequence I

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

Easy#2900
LeetCode Problem

Longest Unequal Adjacent Groups Subsequence I

Problem Statement

You are given a string array words and a binary array groups both of length n. A subsequence of words is alternating if for any two consecutive strings in the sequence, their corresponding elements at the same indices in groups are different (that is, there cannot be consecutive 0 or 1). Your task is to select the longest alternating subsequence from words. Return the selected subsequence. If there are multiple answers, return any of them. Note: The elements in words are distinct.

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

Examples

# Example 1

Input
words = ["e","a","b"], groups = [0,0,1]
Output
["e","b"]

# Example 2

Input
words = ["a","b","c","d"], groups = [1,0,1,1]
Output
["a","b","c"]

Constraints

1 <= n == words.length == groups.length <= 100
1 <= words[i].length <= 10
groups[i] is either 0 or 1.
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 I.

Review your practice with PhantomCodeAI

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