Python/data_structures/arrays
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
..
equilibrium_index_in_array.py Improved Equilibrium Index of an Array. (#10899) 2023-10-25 16:33:35 -04:00
find_triplets_with_0_sum.py add find triplets with 0 sum (3sum) (#10040) 2023-10-12 21:51:53 +02:00
median_two_array.py add median of two sorted array (#9386) 2023-10-04 20:18:59 +02:00
pairs_with_given_sum.py Count pairs with given sum (#10282) 2023-10-12 11:08:55 +02:00
permutations.py Fixed permute_recursive() by passing nums.copy(). Fixes #9014 (#9161) 2023-10-01 00:06:15 -04:00
prefix_sum.py add prefix sum (#7959) 2022-11-04 20:30:32 +13:00
product_sum.py Algorithm: Calculating Product Sum from a Special Array with Nested Structures (#8761) 2023-06-23 10:26:05 +02:00
sparse_table.py Added data_structures/arrays/sparse_table.py (#10437) 2023-10-15 22:13:27 +02:00
sudoku_solver.py Add arrays/sudoku_solver.py (#10623) 2023-10-17 19:07:40 +02:00