Tap here to switch tabs
Problem
Submissions

Problem: Longest Unequal Adjacent Groups Subsequence II

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

Statement

You are given an integer n, an array of strings words, and an array of integers groups, both of length n.

The Hamming distance between two strings of equal length is defined as the number of positions at which the corresponding characters are different.

You need to select the longest subsequence of indices [i0,i1,…,ik−1][i_0, i_1, \dots, i_{k - 1}] from the range [0,n−1][0, n - 1] such that for all 0≤j<k−10 \leq j < k - 1:

  • groups[ij]≠[i_j] \neq groups[ij+1][i_{j + 1}]

  • words[ij][i_j].length == words[ij+1][i_{j + 1}].length

  • The Hamming distance between words[ij][i_j] and words[ij+1][i_{j + 1}] is equal to 11.

Return an array of strings containing the elements of words corresponding to the chosen sequence of indices. If there are multiple valid subsequences of the maximum length, you may return any of them.

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

Constraints:

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

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

  • 1≤1 \leq groups[i] ≤n\leq n

  • 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 II

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

Statement

You are given an integer n, an array of strings words, and an array of integers groups, both of length n.

The Hamming distance between two strings of equal length is defined as the number of positions at which the corresponding characters are different.

You need to select the longest subsequence of indices [i0,i1,…,ik−1][i_0, i_1, \dots, i_{k - 1}] from the range [0,n−1][0, n - 1] such that for all 0≤j<k−10 \leq j < k - 1:

  • groups[ij]≠[i_j] \neq groups[ij+1][i_{j + 1}]

  • words[ij][i_j].length == words[ij+1][i_{j + 1}].length

  • The Hamming distance between words[ij][i_j] and words[ij+1][i_{j + 1}] is equal to 11.

Return an array of strings containing the elements of words corresponding to the chosen sequence of indices. If there are multiple valid subsequences of the maximum length, you may return any of them.

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

Constraints:

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

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

  • 1≤1 \leq groups[i] ≤n\leq n

  • words consists of distinct strings.

  • words[i] consists of lowercase English letters.