diff --git a/src/my_project/interviews/top_150_questions_round_12/is_subsequence.py b/src/my_project/interviews/top_150_questions_round_12/is_subsequence.py new file mode 100644 index 00000000..5c4fffbf --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_12/is_subsequence.py @@ -0,0 +1,18 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def isSubsequence(self, s: str, t: str) -> bool: + + l1, l2 = 0, 0 + + len_s, len_t = len(s), len(t) + + while l1 < len_s and l2 < len_t: + + if s[l1] == t[l2]: + l1 += 1 + + l2 += 1 + + return l1 == len_s \ No newline at end of file diff --git a/tests/test_150_questions_round_12/test_is_subsequence_round_12.py b/tests/test_150_questions_round_12/test_is_subsequence_round_12.py new file mode 100644 index 00000000..f2c14dc6 --- /dev/null +++ b/tests/test_150_questions_round_12/test_is_subsequence_round_12.py @@ -0,0 +1,17 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_12\ +.is_subsequence import Solution + + +class IsSubsequenceTestCase(unittest.TestCase): + + def test_is_subsequence(self): + solution = Solution() + output = solution.isSubsequence(s="abc", t="ahbgdc") + self.assertTrue(output) + + def test_is_no_subsequence(self): + solution = Solution() + output = solution.isSubsequence(s="axc", t="ahbgdc") + self.assertFalse(output) + \ No newline at end of file