[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-11-03 12:25:54 +00:00
parent 42318bb38d
commit 414afc5eec
5 changed files with 24 additions and 15 deletions

View File

@ -5,6 +5,7 @@ Given an array arr[] of size n, the task is to find all the Leaders in the array
Note: The rightmost element is always a leader. Note: The rightmost element is always a leader.
""" """
def array_leader(arr): def array_leader(arr):
leaders = [] leaders = []
for i in range(len(arr)): for i in range(len(arr)):

View File

@ -5,6 +5,7 @@ Output: 60
Explanation: The subarray with maximum product is {60}. Explanation: The subarray with maximum product is {60}.
""" """
def max_product(arr): def max_product(arr):
result = 0 result = 0
@ -15,5 +16,6 @@ def max_product(arr):
result = max(result, current_product) result = max(result, current_product)
return result return result
# Test the function with the provided input # Test the function with the provided input
print(max_product([-1, -3, -10, 0, 60])) # Expected output: 60 print(max_product([-1, -3, -10, 0, 60])) # Expected output: 60

View File

@ -12,6 +12,7 @@ Output: 25
Explanation: The subarray {5, 4, 1, 7, 8} has the largest sum 25. Explanation: The subarray {5, 4, 1, 7, 8} has the largest sum 25.
""" """
def max_subarray(arr): def max_subarray(arr):
result = arr[0] result = arr[0]
@ -22,6 +23,7 @@ def max_subarray(arr):
result = max(result, current_sum) result = max(result, current_sum)
return result return result
# Test the function with the provided inputs # Test the function with the provided inputs
print(max_subarray([2, 3, -8, 7, -1, 2, 3])) # Expected output: 11 print(max_subarray([2, 3, -8, 7, -1, 2, 3])) # Expected output: 11
print(max_subarray([-2, -4])) # Expected output: -2 print(max_subarray([-2, -4])) # Expected output: -2

View File

@ -1,4 +1,4 @@
''' """
Given an array arr[] of size n-1 with integers in the range of [1, n], the task is to find the missing number from the first N integers. Given an array arr[] of size n-1 with integers in the range of [1, n], the task is to find the missing number from the first N integers.
Note: There are no duplicates in the list. Note: There are no duplicates in the list.
@ -10,7 +10,8 @@ Explanation: Here the size of the array is 8, so the range will be [1, 8]. The m
Input: arr[] = {1, 2, 3, 5}, n = 5 Input: arr[] = {1, 2, 3, 5}, n = 5
Output: 4 Output: 4
Explanation: Here the size of the array is 4, so the range will be [1, 5]. The missing number between 1 to 5 is 4 Explanation: Here the size of the array is 4, so the range will be [1, 5]. The missing number between 1 to 5 is 4
''' """
def find_missing_number(arr, n): def find_missing_number(arr, n):
hash = [0] * (n + 1) hash = [0] * (n + 1)
@ -22,4 +23,5 @@ def find_missing_number(arr, n):
return i return i
return -1 return -1
print(find_missing_number([1, 2, 3, 4, 6, 7, 8], 8)) print(find_missing_number([1, 2, 3, 4, 6, 7, 8], 8))

View File

@ -9,11 +9,13 @@ Explanation:
After 1st rotation {9, 1, 3, 5, 7}After 2nd rotation {7, 9, 1, 3, 5} After 1st rotation {9, 1, 3, 5, 7}After 2nd rotation {7, 9, 1, 3, 5}
""" """
def right_rotate(arr, k): def right_rotate(arr, k):
n = len(arr) n = len(arr)
k = k % n k = k % n
arr = arr[n - k :] + arr[: n - k] arr = arr[n - k :] + arr[: n - k]
return arr return arr
# Test the function with the provided input # Test the function with the provided input
print(right_rotate([1, 3, 5, 7, 9], 2)) # Expected output: [7, 9, 1, 3, 5] print(right_rotate([1, 3, 5, 7, 9], 2)) # Expected output: [7, 9, 1, 3, 5]