Công Nghệ

String – 9: Find longest sub-string length with K distinct characters




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/

Công Nghệ
NASUS SIÊU LỖI VỚI " NGỌN GIÁO SHOJIN + NGỌC CHINH PHỤC " + 1020q | TEAM BẠN KHÓC THÉT
Công Nghệ
Bộ ống kính điện thoại 5 trong 1 lens macro, CPL, fisheye, wide, starlight
Công Nghệ
Cách tải gta vice city bản mod hd 2018 – Cướp đường phố bản mod
There are currently no comments.