From b09a35c14280283a9d1c5eeb494688f4b3a0a951 Mon Sep 17 00:00:00 2001 From: TarasMykytiuk Date: Sat, 13 Jun 2026 01:33:00 +0300 Subject: [PATCH 1/6] js taks --- .../calculateSumAndProduct.js | 11 ++++------- .../findCommonItems/findCommonItems.js | 15 +++++++++------ .../hasPairWithSum/hasPairWithSum.js | 18 ++++++++++++++---- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js b/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js index ce738c33..e852b8c3 100644 --- a/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js +++ b/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js @@ -9,21 +9,18 @@ * "product": 30 // 2 * 3 * 5 * } * - * Time Complexity: - * Space Complexity: - * Optimal Time Complexity: + * Time Complexity: before fix O(2N), after double loop removed - O(N) + * Space Complexity: 0(1) - no changes + * Optimal Time Complexity: O(N) * * @param {Array} numbers - Numbers to process * @returns {Object} Object containing running total and product */ export function calculateSumAndProduct(numbers) { let sum = 0; - for (const num of numbers) { - sum += num; - } - let product = 1; for (const num of numbers) { + sum += num; product *= num; } diff --git a/Sprint-1/JavaScript/findCommonItems/findCommonItems.js b/Sprint-1/JavaScript/findCommonItems/findCommonItems.js index 5619ae5d..12782cf8 100644 --- a/Sprint-1/JavaScript/findCommonItems/findCommonItems.js +++ b/Sprint-1/JavaScript/findCommonItems/findCommonItems.js @@ -1,14 +1,17 @@ /** * Finds common items between two arrays. * - * Time Complexity: - * Space Complexity: - * Optimal Time Complexity: + * Time Complexity: worst O(N1 * N2) + * Space Complexity: worst O(max(N1, N2)) + * Optimal Time Complexity: worst become: O(N1 + N2) * * @param {Array} firstArray - First array to compare * @param {Array} secondArray - Second array to compare * @returns {Array} Array containing unique common items */ -export const findCommonItems = (firstArray, secondArray) => [ - ...new Set(firstArray.filter((item) => secondArray.includes(item))), -]; +export const findCommonItems = (firstArray, secondArray) => { + const firstSet = new Set(firstArray); + const secondSet = new Set(secondArray); + secondArray = [...secondSet].filter((element) => firstSet.has(element)) + return secondArray; +}; diff --git a/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js b/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js index dd2901f6..eb80c3fa 100644 --- a/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js +++ b/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js @@ -1,15 +1,15 @@ /** * Find if there is a pair of numbers that sum to a given target value. * - * Time Complexity: - * Space Complexity: - * Optimal Time Complexity: + * Time Complexity: worst O(N!) - factorial + * Space Complexity: O(numbers.length) + * Optimal Time Complexity: worth become O(N) * * @param {Array} numbers - Array of numbers to search through * @param {number} target - Target sum to find * @returns {boolean} True if pair exists, false otherwise */ -export function hasPairWithSum(numbers, target) { +export function hasPairWithSum1(numbers, target) { for (let i = 0; i < numbers.length; i++) { for (let j = i + 1; j < numbers.length; j++) { if (numbers[i] + numbers[j] === target) { @@ -19,3 +19,13 @@ export function hasPairWithSum(numbers, target) { } return false; } + +export function hasPairWithSum(numbers, target) { + + for (let i = 0; i < numbers.length; i++) { + if (numbers.includes(target - numbers[i])) { + return true; + } + } + return false; +} From 08c8476767826e2aa0ee6befa3b49bed7e1c91c4 Mon Sep 17 00:00:00 2001 From: TarasMykytiuk Date: Sat, 13 Jun 2026 01:36:55 +0300 Subject: [PATCH 2/6] js taks+ --- .../removeDuplicates/removeDuplicates.mjs | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/Sprint-1/JavaScript/removeDuplicates/removeDuplicates.mjs b/Sprint-1/JavaScript/removeDuplicates/removeDuplicates.mjs index dc5f7711..f70c6bc5 100644 --- a/Sprint-1/JavaScript/removeDuplicates/removeDuplicates.mjs +++ b/Sprint-1/JavaScript/removeDuplicates/removeDuplicates.mjs @@ -1,36 +1,20 @@ /** * Remove duplicate values from a sequence, preserving the order of the first occurrence of each value. * - * Time Complexity: - * Space Complexity: - * Optimal Time Complexity: + * Time Complexity: O(N*N) quadratic + * Space Complexity: O(N) + * Optimal Time Complexity: become O(N) * * @param {Array} inputSequence - Sequence to remove duplicates from * @returns {Array} New sequence with duplicates removed */ export function removeDuplicates(inputSequence) { const uniqueItems = []; - - for ( - let currentIndex = 0; - currentIndex < inputSequence.length; - currentIndex++ - ) { - let isDuplicate = false; - for ( - let compareIndex = 0; - compareIndex < uniqueItems.length; - compareIndex++ - ) { - if (inputSequence[currentIndex] === uniqueItems[compareIndex]) { - isDuplicate = true; - break; - } - } - if (!isDuplicate) { - uniqueItems.push(inputSequence[currentIndex]); + inputSequence.forEach((element) => { + if (!uniqueItems.includes(element)) { + uniqueItems.push(element); } - } + }); return uniqueItems; } From 2c7df2ba57f76bd59ca63d76d2dae3d01cc1c1c6 Mon Sep 17 00:00:00 2001 From: TarasMykytiuk Date: Sat, 13 Jun 2026 01:46:06 +0300 Subject: [PATCH 3/6] python taks --- .../calculateSumAndProduct.js | 2 +- .../JavaScript/findCommonItems/findCommonItems.js | 2 +- .../JavaScript/hasPairWithSum/hasPairWithSum.js | 10 ---------- .../calculate_sum_and_product.py | 11 +++++------ .../Python/find_common_items/find_common_items.py | 15 ++++++--------- .../Python/has_pair_with_sum/has_pair_with_sum.py | 12 ++++++------ .../Python/remove_duplicates/remove_duplicates.py | 15 +++++---------- 7 files changed, 24 insertions(+), 43 deletions(-) diff --git a/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js b/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js index e852b8c3..1ebcaca7 100644 --- a/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js +++ b/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js @@ -10,7 +10,7 @@ * } * * Time Complexity: before fix O(2N), after double loop removed - O(N) - * Space Complexity: 0(1) - no changes + * Space Complexity: 0(N) - depends on numbers.length * Optimal Time Complexity: O(N) * * @param {Array} numbers - Numbers to process diff --git a/Sprint-1/JavaScript/findCommonItems/findCommonItems.js b/Sprint-1/JavaScript/findCommonItems/findCommonItems.js index 12782cf8..e1d64ea3 100644 --- a/Sprint-1/JavaScript/findCommonItems/findCommonItems.js +++ b/Sprint-1/JavaScript/findCommonItems/findCommonItems.js @@ -2,7 +2,7 @@ * Finds common items between two arrays. * * Time Complexity: worst O(N1 * N2) - * Space Complexity: worst O(max(N1, N2)) + * Space Complexity: worst O(N1 + N2) * Optimal Time Complexity: worst become: O(N1 + N2) * * @param {Array} firstArray - First array to compare diff --git a/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js b/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js index eb80c3fa..ac447ffa 100644 --- a/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js +++ b/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js @@ -9,16 +9,6 @@ * @param {number} target - Target sum to find * @returns {boolean} True if pair exists, false otherwise */ -export function hasPairWithSum1(numbers, target) { - for (let i = 0; i < numbers.length; i++) { - for (let j = i + 1; j < numbers.length; j++) { - if (numbers[i] + numbers[j] === target) { - return true; - } - } - } - return false; -} export function hasPairWithSum(numbers, target) { diff --git a/Sprint-1/Python/calculate_sum_and_product/calculate_sum_and_product.py b/Sprint-1/Python/calculate_sum_and_product/calculate_sum_and_product.py index cfd5cfdf..aff4c9ac 100644 --- a/Sprint-1/Python/calculate_sum_and_product/calculate_sum_and_product.py +++ b/Sprint-1/Python/calculate_sum_and_product/calculate_sum_and_product.py @@ -12,20 +12,19 @@ def calculate_sum_and_product(input_numbers: List[int]) -> Dict[str, int]: "sum": 10, // 2 + 3 + 5 "product": 30 // 2 * 3 * 5 } - Time Complexity: - Space Complexity: - Optimal time complexity: + Time Complexity: O(N*2) + Space Complexity: O(N) + Optimal time complexity: O(N) """ # Edge case: empty list if not input_numbers: return {"sum": 0, "product": 1} sum = 0 - for current_number in input_numbers: - sum += current_number - product = 1 for current_number in input_numbers: + sum += current_number product *= current_number + return {"sum": sum, "product": product} diff --git a/Sprint-1/Python/find_common_items/find_common_items.py b/Sprint-1/Python/find_common_items/find_common_items.py index 478e2efc..994c7f24 100644 --- a/Sprint-1/Python/find_common_items/find_common_items.py +++ b/Sprint-1/Python/find_common_items/find_common_items.py @@ -9,13 +9,10 @@ def find_common_items( """ Find common items between two arrays. - Time Complexity: - Space Complexity: - Optimal time complexity: + Time Complexity: worst O(N1 * N2) + Space Complexity: worst O(N1 + N2) + Optimal time complexity: worst become: O(N1 + N2) """ - common_items: List[ItemType] = [] - for i in first_sequence: - for j in second_sequence: - if i == j and i not in common_items: - common_items.append(i) - return common_items + firstSet = set(first_sequence) + secondSet = set(first_sequence) + return list(firstSet.intersection(secondSet)) diff --git a/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py b/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py index fe2da517..73ff54df 100644 --- a/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py +++ b/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py @@ -7,12 +7,12 @@ def has_pair_with_sum(numbers: List[Number], target_sum: Number) -> bool: """ Find if there is a pair of numbers that sum to a target value. - Time Complexity: - Space Complexity: - Optimal time complexity: + Time Complexity: worst O(N!) - factorial + Space Complexity: O(numbers.length) + Optimal time complexity: worth become O(N) """ + for i in range(len(numbers)): - for j in range(i + 1, len(numbers)): - if numbers[i] + numbers[j] == target_sum: - return True + if (numbers[i] - target_sum) in numbers: + return True return False diff --git a/Sprint-1/Python/remove_duplicates/remove_duplicates.py b/Sprint-1/Python/remove_duplicates/remove_duplicates.py index c9fdbe80..2a5007af 100644 --- a/Sprint-1/Python/remove_duplicates/remove_duplicates.py +++ b/Sprint-1/Python/remove_duplicates/remove_duplicates.py @@ -7,19 +7,14 @@ def remove_duplicates(values: Sequence[ItemType]) -> List[ItemType]: """ Remove duplicate values from a sequence, preserving the order of the first occurrence of each value. - Time complexity: - Space complexity: - Optimal time complexity: + Time complexity: O(N*N) quadratic + Space complexity: O(N) + Optimal time complexity: become O(N) """ - unique_items = [] + unique_items = [] for value in values: - is_duplicate = False - for existing in unique_items: - if value == existing: - is_duplicate = True - break - if not is_duplicate: + if value not in unique_items: unique_items.append(value) return unique_items From a5f19b812b7a8fd8069a94fe130d9ba569a6ca12 Mon Sep 17 00:00:00 2001 From: TarasMykytiuk Date: Sun, 28 Jun 2026 02:52:39 +0100 Subject: [PATCH 4/6] feedback fix 1 --- .../calculateSumAndProduct.js | 4 ++-- .../JavaScript/findCommonItems/findCommonItems.js | 4 ++-- .../JavaScript/hasPairWithSum/hasPairWithSum.js | 13 +++++++------ .../removeDuplicates/removeDuplicates.mjs | 8 +++----- .../Python/find_common_items/find_common_items.py | 2 +- .../Python/has_pair_with_sum/has_pair_with_sum.py | 9 ++++++--- .../Python/remove_duplicates/remove_duplicates.py | 9 +++++---- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js b/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js index 1ebcaca7..030e7212 100644 --- a/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js +++ b/Sprint-1/JavaScript/calculateSumAndProduct/calculateSumAndProduct.js @@ -9,8 +9,8 @@ * "product": 30 // 2 * 3 * 5 * } * - * Time Complexity: before fix O(2N), after double loop removed - O(N) - * Space Complexity: 0(N) - depends on numbers.length + * Time Complexity: O(N) + * Space Complexity: 0(1) - depends on numbers.length * Optimal Time Complexity: O(N) * * @param {Array} numbers - Numbers to process diff --git a/Sprint-1/JavaScript/findCommonItems/findCommonItems.js b/Sprint-1/JavaScript/findCommonItems/findCommonItems.js index e1d64ea3..cf9b9f90 100644 --- a/Sprint-1/JavaScript/findCommonItems/findCommonItems.js +++ b/Sprint-1/JavaScript/findCommonItems/findCommonItems.js @@ -12,6 +12,6 @@ export const findCommonItems = (firstArray, secondArray) => { const firstSet = new Set(firstArray); const secondSet = new Set(secondArray); - secondArray = [...secondSet].filter((element) => firstSet.has(element)) - return secondArray; + const intersection = secondSet.intersection(firstSet); + return [...intersection]; }; diff --git a/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js b/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js index ac447ffa..1c3e2bc7 100644 --- a/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js +++ b/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js @@ -1,8 +1,8 @@ /** * Find if there is a pair of numbers that sum to a given target value. * - * Time Complexity: worst O(N!) - factorial - * Space Complexity: O(numbers.length) + * Time Complexity: worst O(N^2) - square + * Space Complexity: O(1) * Optimal Time Complexity: worth become O(N) * * @param {Array} numbers - Array of numbers to search through @@ -11,11 +11,12 @@ */ export function hasPairWithSum(numbers, target) { - + const numbersSet = new Set(numbers); + const complementsSet = new Set(); for (let i = 0; i < numbers.length; i++) { - if (numbers.includes(target - numbers[i])) { - return true; - } + complementsSet.add(target - numbers[i]) } + const intersection = complementsSet.intersection(numbersSet); + if (intersection.size > 0) return true; return false; } diff --git a/Sprint-1/JavaScript/removeDuplicates/removeDuplicates.mjs b/Sprint-1/JavaScript/removeDuplicates/removeDuplicates.mjs index f70c6bc5..45949f61 100644 --- a/Sprint-1/JavaScript/removeDuplicates/removeDuplicates.mjs +++ b/Sprint-1/JavaScript/removeDuplicates/removeDuplicates.mjs @@ -9,12 +9,10 @@ * @returns {Array} New sequence with duplicates removed */ export function removeDuplicates(inputSequence) { - const uniqueItems = []; + const uniqueItems = new Set(); inputSequence.forEach((element) => { - if (!uniqueItems.includes(element)) { - uniqueItems.push(element); - } + uniqueItems.add(element) }); - return uniqueItems; + return [...uniqueItems]; } diff --git a/Sprint-1/Python/find_common_items/find_common_items.py b/Sprint-1/Python/find_common_items/find_common_items.py index 994c7f24..2f5241dc 100644 --- a/Sprint-1/Python/find_common_items/find_common_items.py +++ b/Sprint-1/Python/find_common_items/find_common_items.py @@ -14,5 +14,5 @@ def find_common_items( Optimal time complexity: worst become: O(N1 + N2) """ firstSet = set(first_sequence) - secondSet = set(first_sequence) + secondSet = set(second_sequence) return list(firstSet.intersection(secondSet)) diff --git a/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py b/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py index 73ff54df..b599798d 100644 --- a/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py +++ b/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py @@ -11,8 +11,11 @@ def has_pair_with_sum(numbers: List[Number], target_sum: Number) -> bool: Space Complexity: O(numbers.length) Optimal time complexity: worth become O(N) """ - + num_set = set(numbers) + complements_set = set() for i in range(len(numbers)): - if (numbers[i] - target_sum) in numbers: - return True + complements_set.add(target_sum - numbers[i]) + intersection = num_set.intersection(complements_set) + if len(intersection) > 0: + return True return False diff --git a/Sprint-1/Python/remove_duplicates/remove_duplicates.py b/Sprint-1/Python/remove_duplicates/remove_duplicates.py index 2a5007af..66e79061 100644 --- a/Sprint-1/Python/remove_duplicates/remove_duplicates.py +++ b/Sprint-1/Python/remove_duplicates/remove_duplicates.py @@ -12,9 +12,10 @@ def remove_duplicates(values: Sequence[ItemType]) -> List[ItemType]: Optimal time complexity: become O(N) """ - unique_items = [] + unique_items = set() + result = [] for value in values: - if value not in unique_items: - unique_items.append(value) + if value not in result: + result.append(value) - return unique_items + return result From d9127d49ec2d48c5113adbce4140f5cf7b4c8345 Mon Sep 17 00:00:00 2001 From: TarasMykytiuk Date: Sun, 28 Jun 2026 23:43:30 +0100 Subject: [PATCH 5/6] feedback fix 2 --- .../JavaScript/hasPairWithSum/hasPairWithSum.js | 11 ++++++----- .../has_pair_with_sum/has_pair_with_sum.py | 16 ++++++++-------- .../remove_duplicates/remove_duplicates.py | 1 - 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js b/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js index 1c3e2bc7..7769f9be 100644 --- a/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js +++ b/Sprint-1/JavaScript/hasPairWithSum/hasPairWithSum.js @@ -11,12 +11,13 @@ */ export function hasPairWithSum(numbers, target) { - const numbersSet = new Set(numbers); - const complementsSet = new Set(); + const checkedNumbers = new Set(); for (let i = 0; i < numbers.length; i++) { - complementsSet.add(target - numbers[i]) + const complement = target - numbers[i]; + if ( checkedNumbers.has(complement)) { + return true; + } + checkedNumbers.add(numbers[i]) } - const intersection = complementsSet.intersection(numbersSet); - if (intersection.size > 0) return true; return false; } diff --git a/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py b/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py index b599798d..a1365805 100644 --- a/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py +++ b/Sprint-1/Python/has_pair_with_sum/has_pair_with_sum.py @@ -7,15 +7,15 @@ def has_pair_with_sum(numbers: List[Number], target_sum: Number) -> bool: """ Find if there is a pair of numbers that sum to a target value. - Time Complexity: worst O(N!) - factorial + Time Complexity: worst O(N^2) - square Space Complexity: O(numbers.length) Optimal time complexity: worth become O(N) """ - num_set = set(numbers) - complements_set = set() - for i in range(len(numbers)): - complements_set.add(target_sum - numbers[i]) - intersection = num_set.intersection(complements_set) - if len(intersection) > 0: - return True + + cheked_numbers = set() + for number in numbers: + complement = target_sum - number + if complement in cheked_numbers: + return True + cheked_numbers.add(number) return False diff --git a/Sprint-1/Python/remove_duplicates/remove_duplicates.py b/Sprint-1/Python/remove_duplicates/remove_duplicates.py index 66e79061..41fddb25 100644 --- a/Sprint-1/Python/remove_duplicates/remove_duplicates.py +++ b/Sprint-1/Python/remove_duplicates/remove_duplicates.py @@ -12,7 +12,6 @@ def remove_duplicates(values: Sequence[ItemType]) -> List[ItemType]: Optimal time complexity: become O(N) """ - unique_items = set() result = [] for value in values: if value not in result: From adb2a9f42524b0b035a6b4b844632e91652dceb7 Mon Sep 17 00:00:00 2001 From: TarasMykytiuk Date: Tue, 30 Jun 2026 03:27:06 +0100 Subject: [PATCH 6/6] remove_duplicates.py set used --- Sprint-1/Python/remove_duplicates/remove_duplicates.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/Python/remove_duplicates/remove_duplicates.py b/Sprint-1/Python/remove_duplicates/remove_duplicates.py index 41fddb25..bf251f90 100644 --- a/Sprint-1/Python/remove_duplicates/remove_duplicates.py +++ b/Sprint-1/Python/remove_duplicates/remove_duplicates.py @@ -11,10 +11,11 @@ def remove_duplicates(values: Sequence[ItemType]) -> List[ItemType]: Space complexity: O(N) Optimal time complexity: become O(N) """ - + added_values = set() result = [] for value in values: - if value not in result: + if value not in added_values: + added_values.add(value) result.append(value) return result