top of page

Dealing with DSA

Public·51 members

Ishika Prasad
Your post made waves — high engagement, real value.

Creator Of The Week

🔥LeetCode Daily – Cracked a Hard One!🧠

Problem: 3405. Count Arrays with K Matching Adjacent Elements📚 Topics: Combinatorics, DP, Modulo Math

💡 Key Insight:

→ Answer = m × C(n−1, k) × (m−1)^(n−1−k) % MOD

Where:

m is the choice for the first element

C(n - 1, k) is the number of ways to choose where equal pairs occur

(m - 1)^{n - 1 - k} handles diversity in remaining slots

🧠 Complexity:

→ Smart blend of choices + combinations + modular exponentiation

✅ Implemented in C++

📌 Time: O(k + log(mod) | Space: O(1)

🎯 Logic meets math. One problem at a time — let’s gooo! 🚀




87 Views

Members

bottom of page