* added merge interval problem on the array ds
* removed typing which is deprecated
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor type hints in merge_intervals function
Updated type hints from List to built-in list for compatibility.
* Enhance merge_intervals function documentation
Added edge cases handling and updated complexity notes.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor docstring and type hints in merge_intervals
Updated type hints and docstring formatting in merge_intervals function.
* Refactor merge_intervals function docstring
Updated docstring formatting and improved error message clarity.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update data_structures/arrays/merge_intervals.py
Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>
* updating DIRECTORY.md
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: priya-sundaram-dev <oc-409d01@agentmail.to>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* feat(arrays): Add in-place array reversal algorithm
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Enhance docstring for reverse_array function
Updated docstring to clarify that the function returns the reversed list.
* Clarify return value in reverse_array function
Updated docstring to clarify that the function returns the reversed list. Modified example usage to display the reversed array correctly.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* Add merge sorted array algorithm
* updating DIRECTORY.md
* Validate input arrays for sorting in merge function
Add validation to check if input arrays are sorted.
* Correct error message assignment in merge_sorted_arrays
Fix variable assignment for error message in merge_sorted_arrays function.
* Fix sorted check for input arrays in merge function
---------
Co-authored-by: JainRamyak <JainRamyak@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* Adding dynamic array implementation
* Adding references
* updating DIRECTORY.md
* Trying to solve pre-commit error of type overload
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Increasing test for dynamic_array.py
---------
Co-authored-by: yashwanth-adimulam <yashwanth-adimulam@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* Suffix Array and LCP Array Implementation
* Delete divide_and_conquer/suffix_array_lcp.py
* Add files via upload
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor Node class to use dataclass
Refactor Node class to use dataclass for cleaner syntax. Update PersistentSegmentTree methods to maintain functionality with the new Node structure.
* updating DIRECTORY.md
* Refactor PersistentSegmentTree implementation
* Refactor Node initialization and update methods
Refactor Node class to properly initialize value and improve type hints. Update PersistentSegmentTree methods for better clarity and maintainability.
* Apply suggestion from @cclauss
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update persistent_segment_tree.py
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Added gas_station.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update gas_station.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update gas_station.py
changes done
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update gas_station.py
* Update gas_station.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update gas_station.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update gas_station.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update gas_station.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
* Refactor gas station circuit solution with NamedTuple
* Clarify gas_stations argument description
Updated the argument description for gas_stations to clarify the attributes.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Add two-pointer method for finding triplets with 0 sum
Implemented a new function to find unique triplets in an array that sum to zero using the two-pointer technique.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* Add comprehensive doctests to disjoint_set.py
- Add doctests for make_set() function with basic initialization tests
- Add doctests for union_set() function with union operations and connected nodes
- Add doctests for find_set() function with path compression verification
- Add doctests for find_python_set() function with error handling
- Add doctests for test_disjoint_set() function with comprehensive example
- All doctests pass and follow project coding standards
- Improves test coverage for fundamental disjoint set data structure
Contributes to #9943
* from dataclasses import dataclass
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Added postfix_to_infix_conversion.py
* Added wikipedia link in postfix_to_infix_conversion.py
* updating DIRECTORY.md
---------
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Adds pairwise iteration algorithm
* Fixed code typo
* updating DIRECTORY.md
* updating DIRECTORY.md
* updating DIRECTORY.md
* Improve documentation for pairwise_iteration_tee
Updated documentation to clarify the use of pairwise iteration and added a reference to the itertools.pairwise function.
* Correct import and update pairwise test cases
Fix import statement for pairwise in pairwise_iteration_tee function and update test cases.
* Fix indentation in pairwise_iteration.py docstring
* Enhance docstring for pairwise iteration
Added docstring explaining the use of itertools.tee for independent iterators.
---------
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
* Add evil_number algorithm in maths/special_numbers
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: SARATHI-78 <sundarasarathi78@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* A stack implementation that tracks min/max element in constant time
* Adding more comments
* Ruff changes
* Fixing doctests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Annotating Stack
* Adding more tests
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* removed nth node
* added link to learn about algo
* Addressed PR feedback
* update bot comments
* update type
* new branch
* new branch
* latest updates with typing
* latest updates with typing
* Add edge cases for equilibrium index
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Refactor docstring in equilibrium_index_in_array.py
Updated docstring examples and formatting for clarity.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* fix:bucket count type
* fixed TypeError
* Refine docstring and adjust return statement
Updated docstring for partition_liked_list method to clarify behavior. Changed return statement from None to None for consistency.
* Add script to map open PRs to modified files
This script lists all open pull requests in the current directory's git repository and maps each file touched by any open PR to its corresponding PR numbers. It outputs the results in GitHub-flavored Markdown format.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add noqa comments for subprocess calls
Add noqa comments to suppress specific linting warnings.
---------
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add XOR Linked List implementation with doctests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add XOR Linked List implementation with doctests
* Add XOR Linked List implementation with doctests
* Add XOR Linked List implementation with doctests
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* updating DIRECTORY.md
* Refine docstring and variable comment in XOR linked list
Updated docstring for clarity and corrected 'ids' to 'IDs'.
* Refactor Node class to use dataclass
Refactor Node class to use dataclass for cleaner syntax.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: cclauss <cclauss@users.noreply.github.com>
Annotate the unambiguous, primitive/container-returning public methods
flagged by ruff ANN201 across data_structures/ (int/bool/float/list/dict
and one fluent self-return). Reduces ANN201 in this directory from 58 to 36.
Element-typed and sentinel-union returns (e.g. node .data getters,
dict|False in the Sudoku solver) are intentionally left for follow-up,
since they warrant generics/TypeVar or a type checker rather than a guess.
Refs #15296
Refactor Node class to use dataclass for attributes and update iter_linked_list to yield node data. Remove print_linked_list function and update merge function to use direct comparison.
* fix: correct treap split() to match docstring for equal values (#7854)
The split() function in treap.py uses `<` comparison but the docstring states that the right subtree should contain values "greater or equal" to the split value. This fix changes `elif value < root.value:` to `elif value <= root.value:` so that equal values go to the right subtree as documented.
Fixes#7854
* Fix typo in Treap node docstringfix: remove accidental typo in Node class docstring
* Fix erase logic in treap.py
Adjust split logic to include the value in the right subtree.
---------
Co-authored-by: Christian Clauss <cclauss@me.com>
* Fixes The Bug In Radix Tree. Issue #11316
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Added Ruff Recommendations
Based on ruff Recommendations
- Removed WhiteSpaces
- Moved the Import to beginning
- Replaced assertTrue with regular assert
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Ruff Fixes : E501 Line too long
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Ruff Fixes : E501 Line too long
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fixes Ruff Error
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Ruff All Fixes
* Improve comments in radix_tree.py
Refactor comments for clarity and correctness in radix_tree.py.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add test function for RadixNode operations
Added a test function for the RadixNode class to validate insertion, search, and deletion of words.
---------
Co-authored-by: Roushan Singh <procoder9973@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
* Add splay tree (self-adjusting BST)
Implements a splay tree with insert, search and delete, each of which
splays the accessed node to the root for amortized O(log n) access and
locality of reference. Includes full type hints and doctests.
Closes#13760
* Make Node a dataclass and add repr doctest (review feedback)
* Fix ty invalid assignment diagnostics
* updating DIRECTORY.md
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix unused typing import
* Fix gradient accumulation type handling
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix automatic differentiation gradient dtype handling
---------
Co-authored-by: kadubhumika <kadubhumika@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>