File: root - text - article - 2019 - 12 - longest-substring-with-k-distinct-characters.txt.txt
Tags: 每日算法题, Longest Substring With K Distinct Characters算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 296 Views, 20037 Search Bots | 94 Words
| Browse | Archive
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Tags: 每日算法题, Longest Substring With K Distinct Characters算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 296 Views, 20037 Search Bots | 94 Words
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Hi, here's your problem today. This problem was recently asked by Amazon:
You are given a string s, and an integer k. Return the length of the longest substring in s that contains at most k distinct characters.
For instance, given the string:
aabcdefff and k = 3, then the longest substring with 3 distinct characters would be defff. The answer should be 5.
Here's a starting point:
Tags: 每日算法题, Longest Substring With K Distinct Characters算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 296 Views, 20037 Search Bots | 94 Words You are given a string s, and an integer k. Return the length of the longest substring in s that contains at most k distinct characters.
For instance, given the string:
aabcdefff and k = 3, then the longest substring with 3 distinct characters would be defff. The answer should be 5.
Here's a starting point:
def longest_substring_with_k_distinct_characters(s, k):
# Fill this in.
print longest_substring_with_k_distinct_characters('aabcdefff', 3)
# 5 (because 'defff' has length 5 with 3 characters)
![Subscribe to Feed Burner Subscribe to Feed Burner](/images/form/rss.gif)
Related Articles
- Fix Brackets
- Algorithm Interview: Longest Consecutive Sequence
- New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
- Non-decreasing Array with Single Modification
- Consecutive Ones
- Daily Interview Puzzle: Minimum Size Subarray Sum
- Find the non-duplicate number
- Daily Interview Puzzle: Falling Dominoes
- [Daily Problem] Validate Balanced Parentheses
- Algorithm Interview Question: Find the Single Element in an Array of Duplicates
©2006~2024 SteakOverCooked - 0.01236 Seconds(s) - 1659.603 KB/s - 20 Online
Memory: 494.36 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">
![](/images/top.jpg)
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !