Hello! I was solving this Leetcode problem yesterday.
I'll rewrite the problem statement once again for convenience
Problem Statement
Examples
Constraints
I would suggest you to solve (in your head or code) this before going further
My Submission (C++)
Now, lets say I have $$$q$$$ Queries of Type:
- $$$1$$$ $$$L$$$ $$$R$$$ $$$k$$$ where-
- $$$L$$$ and $$$R$$$ represent the left and rite endpoints of a subarray in $$$nums$$$ inclusive.
- $$$k$$$ represents the number of operations that can be used to make the entire subarray equal.
For every query, we need to return $$$true$$$ or $$$false$$$ if we are able to make the entire subarray equal.
Here are my observations and approach:
O(n + qlogn) Approach
Not completely positive of my approach so would like to hear any corrections, improvements or suggestions.
So far, we've only seen static/immutable arrays. Lets say I also have a query of Type 2, where
- $$$2$$$ $$$p$$$ :
nums[p] *= -1. (flipping the value at index $$$p$$$).
In this case, how do i device an efficient solution when considering queries of both types? Any Ideas?




