Tap here to switch tabs
Problem
Submissions

Problem: Longest Unequal Adjacent Groups Subsequence I

med
30 min
Try to solve the Longest Unequal Adjacent Groups Subsequence I problem.

Statement

You are given a string array words of length n and a binary integer array groups of the same length n.

A subsequence of words of length kk selected at indices i0<i1<⋯<ik−1i_0 < i_1 < \dots < i_{k-1} is valid if no two adjacent elements in the subsequence share the same group value, meaning groups[iji_j] != groups[ij+1i_{j+1}] for all 0≤j<k−10 \leq j < k - 1.

Return an array of strings representing the longest valid subsequence of words. If there are multiple valid subsequences of the maximum length, return any of them.

Note: A subsequence is a sequence that can be derived from another sequence by deleting zero or more elements without changing the order of the remaining elements.

Constraints:

  • 1≤n==1 \leq n == words.length ==== groups.length ≤100\leq 100

  • 1≤1 \leq words[i].length ≤10\leq 10

  • groups[i] is either 00 or 11

  • words consists of distinct strings

  • words[i] consists of lowercase English letters

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Unequal Adjacent Groups Subsequence I

med
30 min
Try to solve the Longest Unequal Adjacent Groups Subsequence I problem.

Statement

You are given a string array words of length n and a binary integer array groups of the same length n.

A subsequence of words of length kk selected at indices i0<i1<⋯<ik−1i_0 < i_1 < \dots < i_{k-1} is valid if no two adjacent elements in the subsequence share the same group value, meaning groups[iji_j] != groups[ij+1i_{j+1}] for all 0≤j<k−10 \leq j < k - 1.

Return an array of strings representing the longest valid subsequence of words. If there are multiple valid subsequences of the maximum length, return any of them.

Note: A subsequence is a sequence that can be derived from another sequence by deleting zero or more elements without changing the order of the remaining elements.

Constraints:

  • 1≤n==1 \leq n == words.length ==== groups.length ≤100\leq 100

  • 1≤1 \leq words[i].length ≤10\leq 10

  • groups[i] is either 00 or 11

  • words consists of distinct strings

  • words[i] consists of lowercase English letters