Skip to content

Instantly share code, notes, and snippets.

View roshan-jha-23's full-sized avatar
🧿
Focusing

Roshan jha roshan-jha-23

🧿
Focusing
View GitHub Profile
@roshan-jha-23
roshan-jha-23 / faq
Last active March 15, 2024 08:43 — forked from janvichhabra/faq
Longest Subarray With Equal Number Of 0s 1s And 2s
1. What is the meaning of Longest Subarray With Equal Number Of 0s 1s And 2s?
ans -> Longest subarray for the given array which will contain equal number of 0s, 1s, and 2s , we have return its length only in this question.
2. How can we use HashMap in this question?
ans -> We make a hashmap to solve this problem where the key is a string which is represented by "x1-x0 # x2-x1" where the gap between count of 0s and 1s is separated from the gap between count of 1s and 2s by a "#".
3. Why the time complexity is O(n)?
Ans ->The time complexity is linear due to the traversal through the given array.
4. Can we use Hashset instead of HashMap?