diff --git a/src/my_project/interviews/interview_amazon/round_1/algo_3.py b/src/my_project/interviews/interview_amazon/round_1/algo_3.py index e69de29b..746f256d 100644 --- a/src/my_project/interviews/interview_amazon/round_1/algo_3.py +++ b/src/my_project/interviews/interview_amazon/round_1/algo_3.py @@ -0,0 +1,17 @@ +from typing import List + +class Solution: + + def algo_1(self, nums: List[int]): + + + nums = [n for n in nums if n % 7 == 0] + + + return len(nums), nums + + + +solution = Solution() + +print(solution.algo_1(nums=[1,2,7,14,34,35])) \ No newline at end of file diff --git a/src/my_project/interviews/interview_amazon/round_1/algo_4.py b/src/my_project/interviews/interview_amazon/round_1/algo_4.py new file mode 100644 index 00000000..680515bf --- /dev/null +++ b/src/my_project/interviews/interview_amazon/round_1/algo_4.py @@ -0,0 +1,28 @@ +from typing import List + +class Solution: + + def algo_1(self, input_file): + + + with open(input_file, 'r') as infile, \ + open('odd_numbers.txt', 'w') as odd_nums, \ + open('even_numbers.txt', 'w') as even_nums: + + for line in infile: + if not line: + continue + try: + num = int(line) + if num % 2 == 0: + even_nums.write(f'{num}\n') + else: + odd_nums.write(f'{num}\n') + except ValueError: + continue + + + +solution = Solution() + +solution.algo_1(input_file='numbers.txt') \ No newline at end of file diff --git a/src/my_project/interviews/interview_amazon/round_1/even_numbers.txt b/src/my_project/interviews/interview_amazon/round_1/even_numbers.txt new file mode 100644 index 00000000..e5b350fa --- /dev/null +++ b/src/my_project/interviews/interview_amazon/round_1/even_numbers.txt @@ -0,0 +1,3 @@ +4 +8 +10 diff --git a/src/my_project/interviews/interview_amazon/round_1/numbers.txt b/src/my_project/interviews/interview_amazon/round_1/numbers.txt new file mode 100644 index 00000000..e38a5bb5 --- /dev/null +++ b/src/my_project/interviews/interview_amazon/round_1/numbers.txt @@ -0,0 +1,6 @@ +1 +3 +4 +8 +10 +7 \ No newline at end of file diff --git a/src/my_project/interviews/interview_amazon/round_1/odd_numbers.txt b/src/my_project/interviews/interview_amazon/round_1/odd_numbers.txt new file mode 100644 index 00000000..47ae665d --- /dev/null +++ b/src/my_project/interviews/interview_amazon/round_1/odd_numbers.txt @@ -0,0 +1,3 @@ +1 +3 +7 diff --git a/src/my_project/interviews/top_150_questions_round_17/remove_duplicates.py b/src/my_project/interviews/top_150_questions_round_17/remove_duplicates.py new file mode 100644 index 00000000..c9563896 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_17/remove_duplicates.py @@ -0,0 +1,18 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def removeDuplicates(self, nums: List[int]) -> int: + + j = 0 + len_nums = len(nums) + + for i in range(len_nums - 1): + + if nums[i] != nums[i+1]: + nums[j] = nums[i] + j += 1 + + nums[j] = nums[len_nums - 1] + + return j + 1 \ No newline at end of file diff --git a/tests/test_150_questions_round_17/test_remove_duplicates_round_17.py b/tests/test_150_questions_round_17/test_remove_duplicates_round_17.py new file mode 100644 index 00000000..51fd9004 --- /dev/null +++ b/tests/test_150_questions_round_17/test_remove_duplicates_round_17.py @@ -0,0 +1,11 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_17\ +.remove_duplicates import Solution + +class RemoveDuplicatesTestCase(unittest.TestCase): + + def test_remove_duplicates(self): + solution = Solution() + output = solution.removeDuplicates(nums=[1,1,2]) + target = 2 + self.assertEqual(output, target) \ No newline at end of file