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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import List, Union, Collection, Mapping, Optional
from abc import ABC, abstractmethod

class Solution:
def twoSum(self, numbers: List[int], target: int) -> List[int]:

answer = dict()

for k, v in enumerate(numbers):

if v in answer:
return [answer[v]+1, k+1]
else:
answer[target - v] = k

return []
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import List, Union, Collection, Mapping, Optional
from abc import ABC, abstractmethod

class Solution:
def maxArea(self, height: List[int]) -> int:
left = 0
right = len(height) - 1
max_area = 0

while left < right:
# Calculate current area
width = right - left
current_height = min(height[left], height[right])
current_area = width * current_height
max_area = max(max_area, current_area)

# Move pointer with shorter height
if height[left] < height[right]:
left += 1
else:
right -= 1

return max_area
18 changes: 18 additions & 0 deletions tests/test_150_questions_round_22/test_27_two_sum_ii_round_22.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest
from src.my_project.interviews.top_150_questions_round_22\
.ex_27_two_sum_ii import Solution

class TwoSumIIestCase(unittest.TestCase):

def test_is_two_sum(self):
solution = Solution()
output = solution.twoSum(numbers = [2,7,11,15], target = 9)
target = [1,2]
for k, v in enumerate(target):
self.assertEqual(v, output[k])

def test_is_no_two_sum(self):
solution = Solution()
output = solution.twoSum(numbers=[2,7,11,15], target=0)
target = []
self.assertEqual(output, target)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import unittest
from src.my_project.interviews.top_150_questions_round_22\
.ex_28_container_with_most_water import Solution

class ContainerWithMostWaterTestCase(unittest.TestCase):

def test_first_pattern(self):
solution = Solution()
output = solution.maxArea(height = [1,8,6,2,5,4,8,3,7])
target = 49
self.assertEqual(output, target)

def test_second_pattern(self):
solution = Solution()
output = solution.maxArea(height = [1,1])
target = 1
self.assertEqual(output, target)