From 678f60bc1ef5e5abea50c00367211c4482c0d27c Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 16 Jan 2026 04:20:38 -0600 Subject: [PATCH 1/2] adding algo --- .../ex_50_valid_parentheses.py | 21 +++++++++++++++ .../ex_50_valid_parentheses.ts | 26 +++++++++++++++++++ .../test_50_valid_parentheses_round_22.py | 20 ++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/my_project/interviews/top_150_questions_round_22/ex_50_valid_parentheses.py create mode 100644 src/my_project/interviews_typescript/top_150_questions_round_1/ex_50_valid_parentheses.ts create mode 100644 tests/test_150_questions_round_22/test_50_valid_parentheses_round_22.py diff --git a/src/my_project/interviews/top_150_questions_round_22/ex_50_valid_parentheses.py b/src/my_project/interviews/top_150_questions_round_22/ex_50_valid_parentheses.py new file mode 100644 index 00000000..ebc42315 --- /dev/null +++ b/src/my_project/interviews/top_150_questions_round_22/ex_50_valid_parentheses.py @@ -0,0 +1,21 @@ +from typing import List, Union, Collection, Mapping, Optional +from abc import ABC, abstractmethod + +class Solution: + def isValid(self, s): + + dic_parentheses = {'(':')','[':']','{':'}'} + + check_list = list() + + for p in s: + + if p in dic_parentheses: + check_list.append(p) + else: + if len(check_list) == 0 or \ + dic_parentheses[check_list.pop()] != p: + + return False + + return len(check_list) == 0 diff --git a/src/my_project/interviews_typescript/top_150_questions_round_1/ex_50_valid_parentheses.ts b/src/my_project/interviews_typescript/top_150_questions_round_1/ex_50_valid_parentheses.ts new file mode 100644 index 00000000..c06d1521 --- /dev/null +++ b/src/my_project/interviews_typescript/top_150_questions_round_1/ex_50_valid_parentheses.ts @@ -0,0 +1,26 @@ +function isValid(s: string): boolean { + + const dicParentheses: {[key: string]: string} = { + '(': ')', + '[': ']', + '{': '}' + } + + const checkList: string[] = [] + + for (const p of s){ + if (p in dicParentheses){ + checkList.push(p) + }else{ + if (checkList.length === 0 || + dicParentheses[checkList.pop()!] !== p){ + return false + } + } + } + + return checkList.length === 0 + + + +}; diff --git a/tests/test_150_questions_round_22/test_50_valid_parentheses_round_22.py b/tests/test_150_questions_round_22/test_50_valid_parentheses_round_22.py new file mode 100644 index 00000000..32c9261a --- /dev/null +++ b/tests/test_150_questions_round_22/test_50_valid_parentheses_round_22.py @@ -0,0 +1,20 @@ +import unittest +from src.my_project.interviews.top_150_questions_round_22\ +.ex_50_valid_parentheses import Solution + +class ValidParenthesesTestCase(unittest.TestCase): + + def test_is_valid_parentheses(self): + solution = Solution() + output = solution.isValid(s='()') + self.assertTrue(output) + + def test_is_no_valid_parentheses_pattern_1(self): + solution = Solution() + output = solution.isValid(s='(]') + self.assertFalse(output) + + def test_is_no_valid_parentheses_pattern_2(self): + solution = Solution() + output = solution.isValid(s='((') + self.assertFalse(output) \ No newline at end of file From e94bd5cc05129b0942a043cc2e739661e75f6a2b Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 16 Jan 2026 04:21:41 -0600 Subject: [PATCH 2/2] adding algo --- .../top_150_questions_round_1/ex_50_valid_parentheses.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/my_project/interviews_typescript/top_150_questions_round_1/ex_50_valid_parentheses.ts b/src/my_project/interviews_typescript/top_150_questions_round_1/ex_50_valid_parentheses.ts index c06d1521..d24b70c1 100644 --- a/src/my_project/interviews_typescript/top_150_questions_round_1/ex_50_valid_parentheses.ts +++ b/src/my_project/interviews_typescript/top_150_questions_round_1/ex_50_valid_parentheses.ts @@ -20,7 +20,5 @@ function isValid(s: string): boolean { } return checkList.length === 0 - - };