Problem statement

https://binarysearch.com/problems/Longest-Anagram-Subsequence/

Solution

Create counter for each string, then find intersection and return sum of frequencies.

Complexity

It is O(m+n) for time and O(26) for space.

Code

class Solution:
    def solve(self, a, b):
        return sum((Counter(a) & Counter(b)).values())