LeetCode solutions

3143. Longest Unequal Adjacent Groups Subsequence I

My accepted Python solution to LeetCode problem 3143, Longest Unequal Adjacent Groups Subsequence I, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2026-01-02.

python
class Solution:
    def getLongestSubsequence(self, words: List[str], groups: List[int]) -> List[str]:
        result = [words[0]]
        prev_group = groups[0]
        
        for i in range(1, len(words)):
            if groups[i] != prev_group:
                result.append(words[i])
                prev_group = groups[i]
        
        return result

Source