To the Top
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 | 230 Views, 18113 Search Bots | 94 Words

Subscribe to Feed Burner | Browse | Archive
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:


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)
Tags: 每日算法题, Longest Substring With K Distinct Characters算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 230 Views, 18113 Search Bots | 94 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Running Median
  2. Daily Interview Problem: Find the Number of Islands
  3. Floor and Ceiling of a Binary Search Tree
  4. Daily Interview Problem: Merge K Sorted Linked Lists
  5. Daily Interview Problem: Queue Using Two Stacks
  6. Algorithm Interview: Subarray With Target Sum
  7. Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
  8. [Daily Problem] Validate Balanced Parentheses
  9. Algorithm Interview Question: Find the Single Element in an Array of Duplicates
  10. Most Frequent Subtree Sum

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />