-
Notifications
You must be signed in to change notification settings - Fork 2
Graphs | Vertex & Graph implementations #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BrianLusina
wants to merge
74
commits into
main
Choose a base branch
from
feat/graphs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 70 commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
f911604
feat(vertex): add adjacent vertex
BrianLusina dbe61b5
Merge branch 'main' into feat/graphs
BrianLusina 53aa2f4
refactor(datastructures, graphs): refactor edge implementation
BrianLusina 69d657a
updating DIRECTORY.md
502928b
feat(puzzles, datastructures): find closest value in bst
BrianLusina 44c442d
updating DIRECTORY.md
ac33051
refactor(datastructures, binary-search-tree, puzzles): remove the use…
BrianLusina badaa22
feat(algorithms, sliding-window): repeated dna sequences
BrianLusina b934a2d
updating DIRECTORY.md
50547f3
chore(algorithms, sliding-window, find-repeated-dna-sequences: minor …
BrianLusina 1e5f6da
chore: add validation for dna sequences
BrianLusina 8e19362
feat(strings, anagrams): group anagrams
BrianLusina 60234c8
updating DIRECTORY.md
7b997b0
test: add parameterized tests
BrianLusina 46edc29
refactor(datastructures, trees): add return type
BrianLusina 736d8f3
feat(arrays, matrices): set matrix to zero
BrianLusina 16b6e36
updating DIRECTORY.md
232c1ac
chore(arrays, matrices: documentation fixes
BrianLusina 4d8302b
feat(arrays, subarrays): count subarrays with fixed bounds
BrianLusina e8a7919
updating DIRECTORY.md
bd2fd35
refactor(arrays, subarrays): add doctests and edge cae
BrianLusina 7543aca
refactor(algorithms, graphs, course-schedule): additional alternative…
BrianLusina 34dda31
updating DIRECTORY.md
a5811b8
ci(github): update pre-commit workflow versions
BrianLusina 95f2f54
docs(readme): add codacy badge
BrianLusina 0c8fe96
chore(lint): format fixes
BrianLusina e59bb5f
chore(lint): minor format fixes
BrianLusina acb0d35
feat(datastructures, bst): construct min height bst
BrianLusina bbb1880
feat(datastructures, binary-tree): zig zag level order traversal
BrianLusina ec4c328
refactor(binary-trees, zig-zag-level-order): add else condition
BrianLusina b0464e6
feat(strings, datastructures): similar string groups with disjoint se…
BrianLusina 68432de
updating DIRECTORY.md
4a09528
refactor(datastructures, union-find): add type hints and doc comments
BrianLusina 689437f
refactor(strings, similar string groups): is similar string function
BrianLusina 2a95ed1
refactor(strings, similar-string-groups): add length check
BrianLusina b1e465e
feat(strings, self-contained-substring): longest self contained subst…
BrianLusina 6266c10
updating DIRECTORY.md
aad41ed
refactor(strings, longest_self_contained_substring): add type hints
BrianLusina daee2ef
test(strings, longest_self_contained_substring): doc tests
BrianLusina e635cfe
feat(heaps, maximal-score): maximal score after k operations
BrianLusina 0c0965c
updating DIRECTORY.md
f6e12d6
doc(readme, max-score-after-k-ops): minor doc update
BrianLusina 7e92ec7
feat(data-structures, trie, stream-checker): adds a stream checker data
BrianLusina d8f758a
updating DIRECTORY.md
b7f1b76
feat(strings, trie): is prefix of word
BrianLusina d24f593
chore: remove redundant test
BrianLusina 426ac00
refactor(trie): fix none check
BrianLusina 0222ac7
updating DIRECTORY.md
2d9ffa0
feat(algorithms, arrays, binary search): two sum less than k
BrianLusina 688c6bd
updating DIRECTORY.md
9d6cd6d
docs: remove missing example
BrianLusina af2d1f3
feat(algorithms, binary-search): max runtime for n computers
BrianLusina 3788d94
updating DIRECTORY.md
2246a92
feat(datastructures, binary tree): lowest common ancestor
BrianLusina c0919e4
updating DIRECTORY.md
0fe2997
feat(datastructures, binary tree): lowest common ancestor
BrianLusina 58f5e42
chore(lint): format files
BrianLusina 07c7752
chore(lint): format files
BrianLusina 512075b
feat(trees): longest common suffix queries
BrianLusina 9a24ee7
updating DIRECTORY.md
49d4166
refactor(strings, anagram): is anagram improvements
BrianLusina 077817c
feat(trees): find kth largest in binary search tree
BrianLusina 1ed25b4
feat(data structures, heaps): min cost to connect sticks
BrianLusina 330873c
refactor(datastructures, linkedlist): cleans up reverse_between method
BrianLusina e3838ff
feat(data structures, linked list): additional algorithm to reverse_b…
BrianLusina 85adea4
updating DIRECTORY.md
2c8b4c1
reafactor(data structure, linked list): add negative values validation
BrianLusina 46f9f29
feat(data structures, binary trees): min camera cover
BrianLusina 678e2fd
feat(data structures, graphs): frog position after t seconds
BrianLusina d851df5
updating DIRECTORY.md
b50ebc0
feat(graphs, bfs): closest node in tree along path
BrianLusina 9dbfe8c
updating DIRECTORY.md
b04dc64
Merge branch 'main' into feat/graphs
BrianLusina 0730fe9
chore(lint): fix linting issues
BrianLusina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Two Sum Less Than K | ||
|
|
||
| Given an array of integers, nums, and an integer k, find the maximum sum of two elements in nums less than k. Otherwise, | ||
| return −1 if no such pair exists. | ||
|
|
||
| Constraints | ||
|
|
||
| - 1 ≤ nums.length ≤ 100 | ||
| - 1 ≤ nums[i] ≤ 10^3 | ||
| - 1 ≤ k ≤ 10^3 | ||
|
|
||
| ## Examples | ||
|
|
||
|  | ||
|  | ||
|  | ||
|  | ||
|
|
||
| ## Related Topics | ||
|
|
||
| - Array | ||
| - Two Pointers | ||
| - Binary Search |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| from typing import List | ||
|
|
||
|
|
||
| def two_sum_less_than_k(nums: List[int], k: int) -> int: | ||
| """ | ||
| Finds the maximum sum of two elements in a given list of numbers that is less than k. | ||
| Uses binary search to achieve a time complexity of O(n log n) and find the maximum sum of two elements | ||
| that is less than k. It takes the nums array and the target value k as input. | ||
| Args: | ||
| nums (List[int]): A sorted list of integers | ||
| k int: The target value to search for | ||
| Returns: | ||
| The maximum sum of two elements that is less than k | ||
| """ | ||
| max_sum = -1 | ||
|
|
||
| # sort the numbers in ascending order to facilitate binary search | ||
| nums.sort() | ||
|
|
||
| for x in range(len(nums)): | ||
| # find the maximum sum of two elements that is less than k, with the first element being nums[x] | ||
| y = search(nums, k - nums[x], x + 1) | ||
| if y > x: | ||
| # update max_sum with the maximum sum found so far | ||
| max_sum = max(max_sum, nums[x] + nums[y]) | ||
|
|
||
| return max_sum | ||
|
|
||
|
|
||
| def search(nums: List[int], target: int, start: int) -> int: | ||
| """ | ||
| Searches for a number that is less than the target in a sorted list of numbers. | ||
| Uses binary search to achieve a time complexity of O(log n) and find the index j such that the sum | ||
| nums[i]+nums[j] < k. It takes the nums array, target value, and the start range of the search as input. | ||
| Args: | ||
| nums (List[int]): A sorted list of integers | ||
| target int: The target value to search for | ||
| start int: The starting index of the search range | ||
| Returns: | ||
| The index of the number that is less than the target, or -1 if no such number is found | ||
| """ | ||
| left, right = start, len(nums) - 1 | ||
| result = -1 | ||
|
|
||
| while left <= right: | ||
| # calculate the midpoint of the search range | ||
| mid = (left + right) // 2 | ||
| if nums[mid] < target: | ||
| # update result to mid and move left to mid + 1 to look for larger values. | ||
| result = mid | ||
| left = mid + 1 | ||
| else: | ||
| # move right to mid - 1 to check smaller values. | ||
| right = mid - 1 | ||
|
|
||
| return result |
Binary file added
BIN
+51.6 KB
algorithms/arrays/two_sum_less_k/images/examples/two_sum_less_k_example_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+56.5 KB
algorithms/arrays/two_sum_less_k/images/examples/two_sum_less_k_example_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+56 KB
algorithms/arrays/two_sum_less_k/images/examples/two_sum_less_k_example_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+55.4 KB
algorithms/arrays/two_sum_less_k/images/examples/two_sum_less_k_example_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import unittest | ||
| from . import two_sum_less_than_k | ||
|
|
||
|
|
||
| class TwoSumLessKTestCase(unittest.TestCase): | ||
| def test_1(self): | ||
| """numbers = [4,2,11,2,5,3,5,8], target = 7""" | ||
| numbers = [4, 2, 11, 2, 5, 3, 5, 8] | ||
| target = 7 | ||
| expected = 6 | ||
| actual = two_sum_less_than_k(numbers, target) | ||
| self.assertEqual(expected, actual) | ||
|
|
||
| def test_2(self): | ||
| """numbers = [10,20,30], target = 15""" | ||
| numbers = [10, 20, 30] | ||
| target = 15 | ||
| expected = -1 | ||
| actual = two_sum_less_than_k(numbers, target) | ||
| self.assertEqual(expected, actual) | ||
|
|
||
| def test_3(self): | ||
| """numbers = [34,23,1,24,75,33,54,8], k = 60""" | ||
| numbers = [34, 23, 1, 24, 75, 33, 54, 8] | ||
| k = 60 | ||
| expected = 58 | ||
| actual = two_sum_less_than_k(numbers, k) | ||
| self.assertEqual(expected, actual) | ||
|
|
||
| def test_4(self): | ||
| """numbers = [5,5,5,5,5,5], k = 15""" | ||
| numbers = [5, 5, 5, 5, 5, 5] | ||
| k = 15 | ||
| expected = 10 | ||
| actual = two_sum_less_than_k(numbers, k) | ||
| self.assertEqual(expected, actual) | ||
|
|
||
| def test_5(self): | ||
| """numbers = [1,2,3,4,5], k = 3""" | ||
| numbers = [1, 2, 3, 4, 5] | ||
| k = 3 | ||
| expected = -1 | ||
| actual = two_sum_less_than_k(numbers, k) | ||
| self.assertEqual(expected, actual) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
cat -n .github/workflows/pre-commit.yml | head -30Repository: BrianLusina/PythonSnips
Length of output: 852
🌐 Web query:
actions/setup-python latest version GitHub Actions💡 Result:
The latest release is actions/setup-python v6.1.0 — published Nov 25, 2025. [1][2]
Sources:
[1] actions/setup-python Releases (GitHub).
[2] actions/setup-python README / Marketplace page (GitHub).
🌐 Web query:
psf/black latest version GitHub Actions💡 Result:
Use the official action at psf/black@stable to track the latest released Black from PyPI; or pin to a specific release like psf/black@24.4.0 to lock the version. [1][2]
Sources:
Update remaining outdated actions for consistency.
The
checkout@v5andcache@v4upgrades are good, but also update:actions/setup-python@v2→ current latest is v6.1.0psf/black@21.4b0→ usepsf/black@stableor pin to a recent version likepsf/black@24.4.0🤖 Prompt for AI Agents