Skip to content

Diald patch 7 #9356

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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions data_structures/arrays/kadanes_algorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Given an integer array nums, find the subarray with the largest sum, and return its sum.
Example 1:
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
Output: 6
Explanation: The subarray [4,-1,2,1] has the largest sum 6.
Example 2:
Input: nums = [1]
Output: 1
Explanation: The subarray [1] has the largest sum 1.
Example 3:
Input: nums = [5,4,-1,7,8]
Output: 23
Explanation: The subarray [5,4,-1,7,8] has the largest sum 23.
"""


def max_subArray(self, nums: List[int]) -> int:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: max_subArray

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/kadanes_algorithm.py, please provide doctest for the function max_subArray

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: max_subArray

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/kadanes_algorithm.py, please provide doctest for the function max_subArray

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: max_subArray

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/kadanes_algorithm.py, please provide doctest for the function max_subArray

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: max_subArray

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/kadanes_algorithm.py, please provide doctest for the function max_subArray

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: max_subArray

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/kadanes_algorithm.py, please provide doctest for the function max_subArray

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: max_subArray

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/kadanes_algorithm.py, please provide doctest for the function max_subArray

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: max_subArray

As there is no test file in this pull request nor any test function or class in the file data_structures/arrays/kadanes_algorithm.py, please provide doctest for the function max_subArray

# kadane's algorithm#
curr = 0
maxtillnow = -inf
for c in nums:
curr = max(c, curr + c)
maxtillnow = max(curr, maxtillnow)
return maxtillnow


if __name__ == "__main__":
import doctest

doctest.testmod()
43 changes: 43 additions & 0 deletions other/two_sum_advance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Pointer Solution
Example 1:

Input: numbers = [2,7,11,15], target = 9
Output: [1,2]
Explanation: The sum of 2 and 7 is 9.
Therefore, index1 = 1, index2 = 2. We return [1, 2].
Example 2:

Input: numbers = [2,3,4], target = 6
Output: [1,3]
Explanation: The sum of 2 and 4 is 6.
Therefore index1 = 1, index2 = 3. We return [1, 3].
Example 3:

Input: numbers = [-1,0], target = -1
Output: [1,2]
Explanation: The sum of -1 and 0 is -1.
Therefore index1 = 1, index2 = 2. We return [1, 2].
"""


def two_sum(self, numbers: list[int], target: int) -> list[int]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/two_sum_advance.py, please provide doctest for the function two_sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/two_sum_advance.py, please provide doctest for the function two_sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/two_sum_advance.py, please provide doctest for the function two_sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/two_sum_advance.py, please provide doctest for the function two_sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/two_sum_advance.py, please provide doctest for the function two_sum

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/two_sum_advance.py, please provide doctest for the function two_sum

n = len(numbers)
l = 0
r = n - 1
res = []
while l < r:
if numbers[l] + numbers[r] == target:
res.append(l + 1)
res.append(r + 1)
if numbers[l] + numbers[r] > target:
r -= 1
else:
l += 1
res.sort()
return res


if __name__ == "__main__":
import doctest

doctest.testmod()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pandas
pillow
projectq
qiskit
qiskit-aer
requests
rich
scikit-fuzzy
Expand Down