Загрузка...

Leetcode Problem 3445| Max Difference Between even and odd freq -II | Solution In Hindi | Java

🚀 Challenge Description:
Given a string s of digits ('0' to '4') and an integer k, find the maximum frequency difference freq[a] - freq[b] in any substring of s (length ≥ k) such that:

a occurs odd number of times

b occurs even number of times

Return the maximum such difference, or -1 if not possible.

💡 Key Constraints:

Substring must be at least k characters long

Characters a and b can be any digits, not necessarily distinct from each other

At least one valid (odd-even) pair is guaranteed

📘 Example 1
Input: s = "12233", k = 4
Valid: '1' → 1 (odd), '3' → 2 (even)
✅ Output: -1

📘 Example 2
Input: s = "1122211", k = 3
Valid: '2' → 3 (odd), '1' → 2 (even)
✅ Output: 1

📘 Example 3
Input: s = "110", k = 3
No valid (odd, even) pair
✅ Output: -1

🧠 Perfect for mastering:

Sliding window

Frequency analysis

Greedy thinking

🎯 Ideal for DSA prep, coding interviews, and problem-solving speedruns.
👇 Try it now and test your logic!

Видео Leetcode Problem 3445| Max Difference Between even and odd freq -II | Solution In Hindi | Java канала MissLogic - "Where code meets Clarity."
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять