This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |