Python/data_structures
AdityaAtoZ 3d0a409ce1
Improved Equilibrium Index of an Array. (#10899)
* Improved Equilibrium Index of an Array.

This is the modifications made to the original code:

1. Create Doctest Instructions: Python "doctest" can be executed by running the following command: python -m doctest -v equilibrium_index.py.

2. Deleted Argument {size}: Deleted the `size` argument because `len(arr)} allows the array's length to be determined inside the function, simplifying and improving the readability of the function signature.

3. Used {enumerate}: To improve code readability and indicate that we're working with element-index pairs, we iterated through the array using both elements and their indices using the `enumerate` function.

4. Optimized the Loop: To prevent pointless additions, the loop was improved by initializing {left_sum} with the value of the first element (arr[0]). Furthermore, since the beginning and last items (0 and size - 1) cannot be equilibrium indices, there is no need to check them, saving further computations.

* [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>
2023-10-25 16:33:35 -04:00
..
arrays Improved Equilibrium Index of an Array. (#10899) 2023-10-25 16:33:35 -04:00
binary_tree Add dataclasses to binary_search_tree.py (#10920) 2023-10-25 16:28:23 -04:00
disjoint_set Add more ruff rules (#8767) 2023-05-26 09:34:17 +02:00
hashing Ruff pandas vet (#10281) 2023-10-11 14:30:02 -04:00
heap Solving the Top k most frequent words problem using a max-heap (#8685) 2023-04-27 23:02:07 +05:30
linked_list Use dataclasses in circular_linked_list.py (#10884) 2023-10-24 08:45:36 -04:00
queue [bug fixing] Edge case of the double ended queue (#9823) 2023-10-05 10:00:48 -04:00
stacks added implementing stack using two queues (#10076) 2023-10-15 18:41:29 +02:00
trie Fix radix_tree.py insertion fail in ["*X", "*XX"] cases (#8870) 2023-07-24 11:29:05 +02:00
__init__.py Add __init__.py files in all the directories (#2503) 2020-09-28 19:42:36 +02:00