- Read How to answer a coding interview.
- Read Using sliding window technique to solve coding interview questions.
- Practice coding Array 1 Two Sum
- Practice coding Array 2 Three Sum
- Practice coding Array 3 Max Consecutive Ones III
- Practice coding Array 4 Maximum Product Subarray
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UI comp | |
const startBtn = document.createElement("button"); | |
startBtn.innerHTML = "Start listening"; | |
const result = document.createElement("div"); | |
const processing = document.createElement("p"); | |
document.write("<body><h1>My Siri</h1><p>Give it a try with 'hello', 'how are you', 'what's your name', 'what time is it', 'stop', ... </p></body>"); | |
document.body.append(startBtn); | |
document.body.append(result); | |
document.body.append(processing); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The source code is copied from https://www.tomanthony.co.uk | |
*/ | |
function runcheck(userid) | |
{ | |
var scriptblock = document.createElement("script"); | |
scriptblock.src = "https://www.facebook.com/ajax/pagelet/generic.php/TimelineEntStoryActivityLogPagelet?dpr=2&ajaxpipe=1&ajaxpipe_token=AXjdDM6DZ_aiAeG-&no_script_path=1&data=%7B%22year%22%3A2017%2C%22month%22%3A9%2C%22log_filter%22%3A%22hidden%22%2C%22profile_id%22%3A1059016196%7D&__user=" + userid + "&__a=1&__dyn=7AgNe-4amaxx2u6aJGeFxqeCwKyWzEy4aheC267UqwWhE98nwgU6C4UKK9wPGi2uUG4XzEeUK3uczobrzoeonVUkz8nxm1typ8S2m4pU5LxqrUGcwBx-1-wODBwzg7Gu4pHxx0MxK1Iz8d8vy8yeyES3m6ogUKexeEgy9EhxO2qfyZ1zx69wyQF8uhm3Ch4yEiyocUiVk48a8ky89kdGFUS&__req=fetchstream_8&__be=1&__pc=PHASED%3ADEFAULT&__rev=3832430&__spin_r=3832430&__spin_b=trunk&__spin_t=1524222703&__adt=8&ajaxpipe_fetch_stream=1"; | |
scriptblock.id = userid; | |
scriptblock.onload = function() { show_result(userid, false); }; |
- C.P.A.1 Two Sum
- C.P.A.2 Three Sum
- C.P.A.3 Trapping Rain Water
- C.P.A.4 Max Consecutive Ones III
- C.P.A.5 Maximum Product Subarray
- C.P.A.6 Next Permutation
- C.P.SG.1 Valid Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
# graph is represented by adjacency list: List[List[pair]] | |
# s is the source vertex | |
def dijkstra(graph, s): | |
# set is used to mark finalized vertices | |
visited = set() | |
# an array to keep the distance from s to this vertex. | |
# initialize all distances as infinite, except s | |
dist = [float('inf')] * len(graph) | |
dist[s] = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
# graph is represented by adjacency list: List[List[int]] | |
# s: start vertex | |
# d: destination vertex | |
# based on BFS | |
def find_shortest_path(graph, s, d): | |
# pred[i] stores predecessor of i in the path | |
pred = [-1] * len(graph) | |
# set is used to mark visited vertices | |
visited = set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# graph is represented by adjacency list: List[List[int]] | |
# using DFS to find the topological sorting | |
def topological_sort(graph): | |
# using a stack to keep topological sorting | |
stack = [] | |
# set is used to mark visited vertices | |
visited = set() | |
def recur(current_vertex): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
class Solution(object): | |
def orangesRotting(self, grid): | |
""" | |
:type grid: List[List[int]] | |
:rtype: int | |
""" | |
# corner cases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# graph is represented by adjacency list: List[List[int]] | |
# DFS to detect cyclic | |
def is_cyclic_undirected_graph(graph): | |
# set is used to mark visited vertices | |
visited = set() | |
def is_cyclic_recur(current_vertex, parent): | |
# mark it visited | |
visited.add(current_vertex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# graph is represented by adjacency list: List[List[int]] | |
# DFS to detect cyclic | |
def is_cyclic_directed_graph(graph): | |
# set is used to mark visited vertices | |
visited = set() | |
# set is used to keep track the ancestor vertices in recursive stack. | |
ancestors = set() | |
def is_cyclic_recur(current_vertex): | |
# mark it visited |
NewerOlder