#2900

Longest Unequal Adjacent Groups Subsequence I

pupil · 360 · lc easy +23 · 67% accepted · 483 likes · top 73%

Description

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

A subsequence of words is alternating when no two consecutive elements in the subsequence come from the same group value.

Select and return the longest alternating subsequence. If multiple answers exist, any is accepted.

Note: Elements of words are distinct.

Code

1
2
3