✨ Explained in Hindi!! 🤩 Prefix Ka Jaadu🔮
Intuition"Yaar, problem yeh hai ki array ko do parts mein todna hai—ek left aur ek right. Aur left ka sum right se bada ya at least barabar hona chahiye. Matlab
# Intuition 
<img src="https://assets.leetcode.com/users/images/e6e437b6-a4c0-4c91-beaf-540d635534d9_1735895579.0807717.png" width="200" height="30">

"Yaar, problem yeh hai ki array ko do parts mein todna hai—ek left aur ek right. Aur left ka sum right se bada ya at least barabar hona chahiye. Matlab, socho ek jagah cut lagao aur check karo, 'Left ka paisa zyada hai kya?' Bas wahi karna hai efficiently!"

---

# Approach

### 1. **Prefix Sum ka Jaadu**
"Sabse pehle hum ek prefix sum array banate hain—samjho yeh ek jaadu hai jo cumulative sum ko store karta hai. Iska fayda yeh hai ki kisi bhi subarray ka sum fatafat nikal lenge, bina baar-baar calculate kiye."

### 2. **Extreme Values Ka Scene**
"Ab yeh array na kabhi kabhi overdramatic hoti hai, jaise `-100000` ya `100000`. So, hum inko thoda adjust karte hain: `-100000` ko `-1` aur `100000` ko `1` banake simple kar diya. Matlab zyada emotional hone ka nahi!"

### 3. **Split Check Karna**
"Har index pe (0 se leke n-2 tak) hum yeh dekhte hain ki:
- Left ka sum kya hai: `pre[i]`
- Right ka sum kya hai: `pre[n-1] - pre[i]`
Aur agar left ka paisa right se zyada ya barabar hai, toh valid counter ko 'Ek aur add kar de bhai!'"

### 4. **Finally, Answer De Do**
"Ab jitne valid splits mile, unka total return kar denge. Simple hai na?"

---

<img src="https://assets.leetcode.com/users/images/0c30b11f-1261-400c-be69-df125c0dc601_1735895328.2966905.png" width="200" height="30">

# Code Walkthrough

"Yeh dekho, code kaise kaam kar raha hai. Thoda focus maar lo! 👇

# Code
```cpp []
class Solution {
public:
   int waysToSplitArray(vector<int>& nums) {
    int n = nums.size();
    vector<long long> pre(n, 0);  // Prefix sum ka jugad
    long long sum = 0;

    // Prefix sum banate hue edge cases sambhalo
    for (int i = 0; i < n; i++) {
        if (nums[i] == -100000) nums[i] = -1;  // Emotional values ko handle karo
        else if (nums[i] == 100000) nums[i] = 1;
        sum += (nums[i] % 100000);  // Sum mein contribution
        pre[i] = sum;
    }

    int valid = 0;

    // Har split ko check karo
    for (int i = 0; i < n - 1; i++) {
        if (pre[i] >= pre[n - 1] - pre[i]) {
            valid++;  // Ek aur valid split mila!
        }
    }
    return valid;  // Answer dedo yaar
   }
};

```
```java []
// Java Solution
class Solution {
    public int waysToSplitArray(int[] nums) {
        int n = nums.length;
        long[] prefix = new long[n];  // Prefix sum ka jugad
        long sum = 0;

        // Prefix sum banate hue edge cases sambhalo
        for (int i = 0; i < n; i++) {
            if (nums[i] == -100000) nums[i] = -1;  // Emotional values ko handle karo
            else if (nums[i] == 100000) nums[i] = 1;
            sum += nums[i] % 100000;  // Sum mein contribution
            prefix[i] = sum;
        }

        int valid = 0;

        // Har split ko check karo
        for (int i = 0; i < n - 1; i++) {
            if (prefix[i] >= prefix[n - 1] - prefix[i]) {
                valid++;  // Ek aur valid split mila!
            }
        }
        return valid;  // Answer dedo yaar
    }
}

```
```python []
# Python Solution
class Solution:
    def waysToSplitArray(self, nums: List[int]) -> int:
        n = len(nums)
        prefix = [0] * n  # Prefix sum ka jugad
        total_sum = 0

        # Prefix sum banate hue edge cases sambhalo
        for i in range(n):
            if nums[i] == -100000:
                nums[i] = -1  # Emotional values ko handle karo
            elif nums[i] == 100000:
                nums[i] = 1
            total_sum += nums[i] % 100000  # Sum mein contribution
            prefix[i] = total_sum

        valid = 0

        # Har split ko check karo
        for i in range(n - 1):
            if prefix[i] >= prefix[-1] - prefix[i]:
                valid += 1  # Ek aur valid split mila!

        return valid  # Answer dedo yaar

```



# Complexity

## Time Complexity
- Prefix sum banane mein lagega $$O(n)$$.  
- Split check karne mein bhi $$O(n)$$.  
- Toh total: **$$O(n)$$**.  
"Matlab fast hai, chill karo!"

## Space Complexity
- Prefix sum array ko store karne ke liye $$O(n)$$ space.  
- Aur koi bada space nahi use ho raha. Bas itna hi.

---

# Key Notes
Samjho, prefix sum toh yaar ultimate hack hai yaha. Aur extreme values ka drama handle karke kaafi efficient solution ban gaya. Mazedaar baat yeh hai ki code bada smartly kaam kar raha hai!

---
Kya samjh aa gaya? Aur nahi toh puch lo, bina jhijhak! 😄
![image.png](https://assets.leetcode.com/users/images/9a8582a6-a3f3-440b-b9b0-2ffc49912b10_1735895181.3220189.png)




['C++']