Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Ways to Partition an Array

Try to solve the Maximum Number of Ways to Partition an Array problem.

Statement

You are given a 00 indexed integer array nums of length n and an integer k.

You are allowed to choose at most one element in nums and replace its value with k. Alternatively, you may choose to leave the array unchanged.

A pivot index pivot defines a valid partition if 1≤1 \leq pivot <n< n and the sum of the prefix subarray nums from index 00 to pivot −1- 1 is equal to the sum of the suffix subarray nums from index pivot to n −1- 1.

Return the maximum number of valid partitions you can obtain after modifying at most one element.

Constraints:

  • n ==== nums.length

  • 2≤2 \leq n ≤105\leq 10^5

  • −105≤-10^5 \leq k, nums[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Ways to Partition an Array

Try to solve the Maximum Number of Ways to Partition an Array problem.

Statement

You are given a 00 indexed integer array nums of length n and an integer k.

You are allowed to choose at most one element in nums and replace its value with k. Alternatively, you may choose to leave the array unchanged.

A pivot index pivot defines a valid partition if 1≤1 \leq pivot <n< n and the sum of the prefix subarray nums from index 00 to pivot −1- 1 is equal to the sum of the suffix subarray nums from index pivot to n −1- 1.

Return the maximum number of valid partitions you can obtain after modifying at most one element.

Constraints:

  • n ==== nums.length

  • 2≤2 \leq n ≤105\leq 10^5

  • −105≤-10^5 \leq k, nums[i] ≤105\leq 10^5