---
# System prepended metadata

title: 'Compare Strings <img src="https://img.shields.io/badge/-easy-brightgreen">'
tags: [data_structure_python]

---

---
tags: data_structure_python
---

# Compare Strings <img src="https://img.shields.io/badge/-easy-brightgreen">

![](https://i.imgur.com/FEwpSn2.png)

# Solution

```python=
def compare_strings(A, B):
    # n = len(A).
    # m = len(B)
    # Time Complexity: O(n + m).
    # Space Complexity: O(m).
    A = A.split(',')
    B = B.split(',')
    res = []

    for b in B:
        count = 0
        # 1. Find smallest character among A and B.
        small_b = min(b)
        # 2. Compute frequency of A and B smallest character.
        freq_b = b.count(small_b)
        for a in A:
            small_a = min(a)
            freq_a = a.count(small_a)
            # 3. Compare frequency.
            if freq_a < freq_b:
                count += 1
        res.append(count)
    # 4. Returns number of strings in A strictly smaller than B.
    return res
```