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/36fcd85b0af100e82fe2c3625b783f8b to your computer and use it in GitHub Desktop.
Save jianminchen/36fcd85b0af100e82fe2c3625b783f8b to your computer and use it in GitHub Desktop.
January 25 2018 first algorithm in my mock interview, the interviewer asked me to walk through the ideas how to solve the problem.
Given a set of integers, e.g. {1,3,2}, and an array of random integers, e.g.
[1, 2, 2, 5, 4, 0, 1, 1, 2, 2, 0, 3,3]
Find the shortest continuous subarray that contains all of the values from the set.
Result: [1, 2, 2, 0, 3]
Keywords:
given a set with integer -> >0, distinct
given an random integers
Ask for:
Shortest -> greedy
conintuous -> stop ->
subarray ->
return subarray itself ->
minLength =
It is find smallest substring conataing keys.
It is
code review, stackexchange.com
slide windows
left pointer
right pointer
slidewindow
-> find the substring containing all keys
-> determine if slide left pointer
-> number is not in the set
-> number is in the set,but 1 -> need
-> 0 ->
-> -1
-> substring slid windows -> continue
-> right line 29 -> containing
left side pointer
minwindow length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment