Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/83b9378a5d99fd3b5ffb75120b220bd4 to your computer and use it in GitHub Desktop.
Save jianminchen/83b9378a5d99fd3b5ffb75120b220bd4 to your computer and use it in GitHub Desktop.
Find smallest substring containg all keys
using System;
class Solution
{
public static string GetShortestUniqueSubstring(char[] arr, string str)
{
// your code goes here
}
static void Main(string[] args)
{
}
}
'x', 'y', 'z' -> dictionary<'x', 1, 'x':1, 'y':1,'z':1, 3 keys
"xyyzyzyx"
| -> x -> found One key
|| -> xy -> read y -> 'y' - 0, 2 < 3 -> substring
| | -> xyy -> 'y' -> -1, 2 < 3
| |-> xyyz -> 'z' -> 0, 3 == 3, "xyyz", 4, "zyx"
| -> x -> 'x': 0 -> 1, foundKey = 2
| -> yyzy ->
....
minimum substring "zyx"
The time complexity: O(n)
substring is different from subsequence
define by start/ end position -> how to define "xyyz" ->
Leetcode first 200 questions - easy question -> read discussion - go over easy question - two sum problem
- 20 algorithms easy questions - as many as -> learn how to analyze the problem ->
-> read one algorithm at least 3 ideas
-> bring up your intelligent ->
-> math, logic, reasoning, principle -> simple math, simple logic
-> record how many hours ->
-> 2 + 2 + 2 + ...,
https://www.linkedin.com/in/jianminchen
http://juliachencoding.blogspot.ca/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment