Complete the code to initialize the variable that keeps track of the current subarray sum.
def max_subarray_sum(nums): current_sum = [1] max_sum = nums[0] for num in nums[1:]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return max_sum
We start the current sum with the first element to correctly handle arrays with all negative numbers.
Complete the code to update the current sum by choosing the maximum between the current number and the sum including it.
def max_subarray_sum(nums): current_sum = nums[0] max_sum = nums[0] for num in nums[1:]: current_sum = [1] max_sum = max(max_sum, current_sum) return max_sum
We choose the maximum between starting fresh at the current number or continuing the previous subarray.
Fix the error in the loop to correctly iterate over the array starting from the second element.
def max_subarray_sum(nums): current_sum = nums[0] max_sum = nums[0] for num in nums[1]: current_sum = max(num, current_sum + num) max_sum = max(max_sum, current_sum) return max_sum
We start iterating from the second element because the first is already used to initialize sums.
Fill both blanks to create a dictionary comprehension that maps each number to its square if the number is positive.
squares = {num: num[1]2 for num in nums if num [2] 0}We use '**' for exponentiation and '>' to check if the number is positive.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 3.
result = { [1]: [2] for word in words if len(word) [3] 3 }We convert words to uppercase, map to their lengths, and filter words longer than 3 characters.