From 684b8c4971cf4b3590a96a3905b658696205c20f Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 12 Jun 2025 04:27:26 -0600 Subject: [PATCH] adding algo --- .../round_4/valid_palindrome.py | 18 ++++++++++++++++++ .../length_of_last_word.py | 9 +++++++++ .../test_length_of_last_word_round_17.py | 11 +++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/my_project/interviews/interview_amazon/round_4/valid_palindrome.py create mode 100644 src/my_project/interviews/top_150_questions_round_17/length_of_last_word.py create mode 100644 tests/test_150_questions_round_17/test_length_of_last_word_round_17.py diff --git a/src/my_project/interviews/interview_amazon/round_4/valid_palindrome.py b/src/my_project/interviews/interview_amazon/round_4/valid_palindrome.py new file mode 100644 index 00000000..0093628e --- /dev/null +++ b/src/my_project/interviews/interview_amazon/round_4/valid_palindrome.py @@ -0,0 +1,18 @@ +import re + +class Solution: + def isPalindrome(self, s: str) -> bool: + + # to lowercase + s = s.lower() + + # remove non-alphanumeric + s = re.sub(pattern='[^a-zA-Z0-9]', repl='', string=s) + + len_s = len(s) + + for i in range(len_s//2): + if s[i] != s[len_s - 1 -i]: + return False + + return True \ No newline at end of file diff --git a/src/my_project/interviews/top_150_questions_round_17/length_of_last_word.py b/src/my_project/interviews/top_150_questions_round_17/length_of_last_word.py new file mode 100644 index 00000000..12a2640a --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_17/length_of_last_word.py @@ -0,0 +1,9 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def lengthOfLastWord(self, s: str) -> int: + + lst_s = s.split() + + return len(lst_s[-1]) \ No newline at end of file diff --git a/tests/test_150_questions_round_17/test_length_of_last_word_round_17.py b/tests/test_150_questions_round_17/test_length_of_last_word_round_17.py new file mode 100644 index 00000000..0bb3da5e --- /dev/null +++ b/tests/test_150_questions_round_17/test_length_of_last_word_round_17.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_17\ +.length_of_last_word import Solution + +class LengthLastWordTestCase(unittest.TestCase): + + def test_length_last_word(self): + solution = Solution() + output = solution.lengthOfLastWord(s="Hello World") + target = 5 + self.assertEqual(output, target) \ No newline at end of file