#2901

Longest Unequal Adjacent Groups Subsequence II

specialist · 875 · lc medium +31 · 51.5% accepted · 573 likes · top 41%

Description

A string array words and an array groups, both of length n, are given.

The Hamming distance between two equal-length strings is the count of positions where they differ.

Find the longest subsequence of indices [i0, i1, ..., ik-1] such that:

- Adjacent groups in the subsequence differ: groups[ij] != groups[ij+1].

- Adjacent words have equal length and Hamming distance 1.

Return the words at those indices in order. If multiple answers exist, any is accepted.

Note: Words in words may differ in length.

Code

1
2
3