Source Code:
Solution:
– We take a Map, which’ll give me info about unique characters present, Map key will be character & value will be the occurrence of that character
– We’ll take a max_length variable, where we’ll store the solution
– we’ll take two variable start & end, which’ll point to 1st character in string initially
– Now we iterate the string & keep on putting character in map. If size of value is greater than K, then we decrease the character from start index. If occurrence becomes 0, we remove from map.
– max_length will be updated by end – start + 1
– At last we return, max_length as answer
Time Complexity: O(n)
Space Complexity: O(n)
Do Watch video for more info
CHECK OUT CODING SIMPLIFIED
★☆★ VIEW THE BLOG POST: ★☆★
I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I’ve published over 400+ videos.
★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★
★☆★ Send us mail at: ★☆★
Email: thecodingsimplified@gmail.com
Nguồn: https://vinhtrinh.com.vn
Xem thêm bài viết khác: https://vinhtrinh.com.vn/cong-nghe/