💥Beat 100%🚨WARNING! YOU’RE MISSING OUT ON EASY SUBSTRINGS! 😱💥🔥
🚨 WARNING! YOU’RE MISSING OUT ON EASY SUBSTRINGS! 😱💥🔥🤯 IntuitionWe need to find substrings that contain all three 📜 letters: 'a', 'b', and 'c'.
Instead of brute
# 🚨 **WARNING! YOU’RE MISSING OUT ON EASY SUBSTRINGS!** 😱💥🔥  

## 🤯 Intuition  
We need to find **substrings** that contain **all three** 📜 letters: `'a'`, `'b'`, and `'c'`.  
Instead of **brute force** (which is slow 🐢), we **track the last seen indices** of `'a'`, `'b'`, and `'c'`!  

## 🛠️ Approach  
1️⃣ Keep an **array `ls = [-1, -1, -1]`** to store the **latest positions** of `'a'`, `'b'`, and `'c'`.  
2️⃣ For each character in `s`, update its **index** in `ls`.  
3️⃣ Once all three appear at least once, the **number of valid substrings** is `1 + min(ls)`.  
4️⃣ Keep **adding to the count!** 🎯  

## 👀 Visualization  
Let's take `s = "abcabc"` as an example:  

| Index (`i`) | Char (`s[i]`) | `ls` (Latest indices of `'a'`, `'b'`, `'c'`) | `min(ls)` | Count ✅ |
|------|------|----------------------|--------|--------|
| 0️⃣  | `'a'` | `[0, -1, -1]`  | ❌ | 0  |
| 1️⃣  | `'b'` | `[0, 1, -1]`  | ❌ | 0  |
| 2️⃣  | `'c'` | `[0, 1, 2]`  | `0`  | `1 + 0 = 1`  |
| 3️⃣  | `'a'` | `[3, 1, 2]`  | `1`  | `1 + 1 = 2`  |
| 4️⃣  | `'b'` | `[3, 4, 2]`  | `2`  | `1 + 2 = 3`  |
| 5️⃣  | `'c'` | `[3, 4, 5]`  | `3`  | `1 + 3 = 4`  |

Final count = **10 valid substrings**! 🎉🔥  

## ⏳ Complexity  
- **Time Complexity:** $$O(n)$$ 🚀 *(One-pass, super efficient!)*  
- **Space Complexity:** $$O(1)$$ 🎯 *(Only storing three indices!)*  


---

## 💻 Python Code  
```python
class Solution:
    def numberOfSubstrings(self, s: str) -> int:
        ls = [-1, -1, -1]  
        count = 0  
        for i in range(len(s)):  
            ls[ord(s[i]) - ord('a')] = i  
            if -1 not in ls:  
                count += 1 + min(ls)  
        return count
```
## 💡 KEY TAKEAWAYS 💡  
✅ **STOP using brute force! This is 1000x faster!** ⚡  
✅ **Tracking latest indices = Instant counting!** 🎯  
✅ **One-pass solution = Super fast!** 🚀  
✅ **Works for any input!** 💡  
✅ **NO extra space! Memory-efficient!** 🧠  

---

![leetcode-girl.webp](https://assets.leetcode.com/users/images/a858115f-03ed-4c53-b5b4-9545e05f83f4_1738996351.220621.webp)


---
## 🔥 **WAIT! BEFORE YOU GO… BIGGEST OPPORTUNITY AWAITS!** 😱  
👉 **DO YOU LOVE FUN DSA CONTENT?** 🚀  
👉 **DO YOU WANT TO CRUSH INTERVIEWS & LEVEL UP?** 💯  
👉 **DO YOU ENJOY SUPER-ENGAGING EXPLANATIONS LIKE THIS?** 🎉  

👀 **THEN WHAT ARE YOU WAITING FOR?!** **CONNECT WITH ME ON LINKEDIN NOW!** 🔥💼  
🔗 **[CLICK HERE & LET’S BUILD TOGETHER!](https://in.linkedin.com/in/dhruv-gohil-2b9724327)** 🚀🔥  
*(Trust me, you don’t want to miss out… You’ll regret it later! 😜)*  

['Hash Table', 'String', 'Sliding Window', 'Python3']