Queue - Print first non-repeating character in given Stream | Using Queue & Map | Java Code
Vložit
- čas přidán 7. 09. 2024
- Source Code:thecodingsimpl...
Solution:
- We implement it using Map (to maintain frequency of character) & queue (to maintain first non-repeating character)
- while iterating each character of stream, we update the frequency of that character in map, If frequency is one, then we add in queue as well.
- Now, to get first non-repeating character, we check the from front of queue, if frequency of that character is 1 then we print the value else we remove that element
- If queue is empty, we remove the element.
Time Complexity: O(n)
Space Complexity: O(n)
Do Watch video for more info
CHECK OUT CODING SIMPLIFIED
/ codingsimplified
★☆★ VIEW THE BLOG POST: ★☆★
thecodingsimpli...
I started my CZcams channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 400+ videos.
★☆★ SUBSCRIBE TO ME ON CZcams: ★☆★
www.youtube.co...
★☆★ Send us mail at: ★☆★
Email: thecodingsimplified@gmail.com
explained beautifully
Thanks. Keep watching.
Gazab sir
🔥🔥🔥🔥
Thanks for your nice feedback. Keep Watching.
I think space complexity if o(1) as the maximum size of queue and hashmap will be 26
yes bro i think same
Amazing tutorial
Thank you! Cheers!
does it not throw tle? miine did
nice
Thanks for you feedback. Keep Watching.
🔥
Thanks.
time complexity??
Hi, as we mentioned in video. Time Complexity is O(n)
@@CodingSimplified How is this O(n). We are also looping through the queue right? I think it will be more than O(n). In worst case O(n2) actually.
@@revanthreddy5759 at max in queue we only have all the 26 chars so it will not be n^2 but n
and space complexity will be o(1) because queue size at max is 26 and same for map max size is 26