Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Think about dynamic programming
Define an array dp[nums.length][2], where dp[i][0] is the max subarray sum including nums[i] and without squaring any element.
dp[i][1] is the max subarray sum including nums[i] and having only one element squared.