Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ Each problem follows this structure:

## Solutions

📊 **Statistics**: 84 problems solved (migrated to new structure)
📊 **Statistics**: 85 problems solved (migrated to new structure)

| Difficulty | Count |
|------------|-------|
| Easy | 59 |
| Easy | 60 |
| Medium | 24 |
| Hard | 1 |

Expand Down
16 changes: 0 additions & 16 deletions String/1684. Count the Number of Consistent Strings.py

This file was deleted.

3 changes: 2 additions & 1 deletion docs/EASY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Easy Problems

Total: 59 problems solved
Total: 60 problems solved

## Solutions

Expand Down Expand Up @@ -46,6 +46,7 @@ Total: 59 problems solved
| 1603 | [Design Parking System](https://leetcode.com/problems/design-parking-system/) | [solution.py](../problems/easy/design_parking_system_1603/solution.py) | [test_solution.py](../problems/easy/design_parking_system_1603/test_solution.py) |
| 1662 | [Check If Two String Arrays Are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/) | [solution.py](../problems/easy/check_if_two_string_arrays_are_equivalent_1662/solution.py) | [test_solution.py](../problems/easy/check_if_two_string_arrays_are_equivalent_1662/test_solution.py) |
| 1672 | [Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/) | [solution.py](../problems/easy/richest_customer_wealth_1672/solution.py) | [test_solution.py](../problems/easy/richest_customer_wealth_1672/test_solution.py) |
| 1684 | [Count the Number of Consistent Strings](https://leetcode.com/problems/count-the-number-of-consistent-strings/) | [solution.py](../problems/easy/count_the_number_of_consistent_strings_1684/solution.py) | [test_solution.py](../problems/easy/count_the_number_of_consistent_strings_1684/test_solution.py) |
| 1773 | [Count Items Matching a Rule](https://leetcode.com/problems/count-items-matching-a-rule/) | [solution.py](../problems/easy/count_items_matching_a_rule_1773/solution.py) | [test_solution.py](../problems/easy/count_items_matching_a_rule_1773/test_solution.py) |
| 1816 | [Truncate Sentence](https://leetcode.com/problems/truncate-sentence/) | [solution.py](../problems/easy/truncate_sentence_1816/solution.py) | [test_solution.py](../problems/easy/truncate_sentence_1816/test_solution.py) |
| 1929 | [Concatenation of Array](https://leetcode.com/problems/concatenation-of-array/) | [solution.py](../problems/easy/concatenation_of_array_1929/solution.py) | [test_solution.py](../problems/easy/concatenation_of_array_1929/test_solution.py) |
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Tags: Array, String, Hash Table
from typing import List


class Solution:
def count_consistent_strings(self, allowed: str, words: List[str]) -> int:
"""
Let A be the length of allowed string, and L be the total number of characters across all words.

Time complexity: O(A + L)
- Creating the set from allowed: O(A)
- Iterating through all words and characters: O(L) total
- Each set lookup (c not in allowed_set) is O(1) on average
- Overall: O(A) + O(L) = O(A + L)

Space complexity: O(A)
- The allowed_set set stores at most A unique characters from allowed
- Other variables (res, is_consistent) use O(1) constant space
- Overall: O(A)
"""
allowed_set = set(allowed)
res = 0
for word in words:
is_consistent = True
for c in word:
if c not in allowed_set:
is_consistent = False
break
if is_consistent:
res += 1
return res
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from tests.base_test import BaseTestSolution
from .solution import Solution


class TestSolution(BaseTestSolution):
solution = Solution()

@pytest.mark.parametrize("method_name, allowed, words, expected, timeout", [
('count_consistent_strings', "ab", ["ad", "bd", "aaab", "baa", "badab"], 2, None),
('count_consistent_strings', "abc", ["a", "b", "c", "ab", "ac", "bc", "abc"], 7, None),
('count_consistent_strings', "cad", ["cc", "acd", "b", "ba", "bac", "bad", "ac", "d"], 4, None),
])
def test_count_consistent_strings(self, method_name, allowed, words, expected, timeout):
self._run_test(self.solution, method_name, (allowed, words,), expected, timeout)
Loading