This file contains hidden or 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
""" | |
This problem was asked by Google. | |
Given two singly linked lists that intersect at some point, find the intersecting node. The lists are non-cyclical. | |
For example, given A = 3 -> 7 -> 8 -> 10 and B = 99 -> 1 -> 8 -> 10, return the node with value 8. | |
In this example, assume nodes with the same value are the exact same node objects. | |
Do this in O(M + N) time (where M and N are the lengths of the lists) and constant space. |
This file contains hidden or 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
""" | |
This problem was asked by Twitter. | |
Implement an autocomplete system. That is, given a query string s and a set of all possible query strings, return all strings in the set that have s as a prefix. | |
For example, given the query string de and the set of strings [dog, deer, deal], return [deer, deal]. | |
Hint: Try preprocessing the dictionary into a more efficient data structure to speed up queries. | |
""" | |
class Node: |
This file contains hidden or 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
""" | |
This problem was asked by Amazon. | |
Given an integer k and a string s, find the length of the longest substring that contains at most k distinct characters. | |
For example, given s = "abcba" and k = 2, the longest substring with k distinct characters is "bcb". | |
""" | |
def longestSubstring(string, k): | |
start, end = 0, k | |
max_len = k |
This file contains hidden or 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
""" | |
This problem was asked by Airbnb. | |
Given a list of integers, write a function that returns the largest sum of non-adjacent numbers. Numbers can be 0 or negative. | |
For example, [2, 4, 6, 2, 5] should return 13, since we pick 2, 6, and 5. [5, 1, 1, 5] should return 10, since we pick 5 and 5. | |
Follow-up: Can you do this in O(N) time and constant space? | |
""" | |
def largestSum(arr): |
This file contains hidden or 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
""" | |
This problem was asked by Google. | |
A unival tree (which stands for "universal value") is a tree where all nodes under it have the same value. | |
Given the root to a binary tree, count the number of unival subtrees. | |
For example, the following tree has 5 unival subtrees: | |
0 |
This file contains hidden or 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
""" | |
This problem was asked by Amazon. | |
There exists a staircase with N steps, and you can climb up either 1 or 2 steps at a time. Given N, write a function that returns the number of unique ways you can climb the staircase. The order of the steps matters. | |
For example, if N is 4, then there are 5 unique ways: | |
1, 1, 1, 1 | |
2, 1, 1 | |
1, 2, 1 |
This file contains hidden or 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
""" | |
This problem was asked by Facebook. | |
Given the mapping a = 1, b = 2, ... z = 26, and an encoded message, count the number of ways it can be decoded. | |
For example, the message '111' would give 3, since it could be decoded as 'aaa', 'ka', and 'ak'. | |
You can assume that the messages are decodable. For example, '001' is not allowed. | |
""" | |
def count(string): | |
n = len(string) | |
return _count(string, n, 0) |
This file contains hidden or 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
library IEEE; | |
use IEEE.STD_LOGIC_1164.ALL; | |
use IEEE.STD_LOGIC_ARITH.ALL; | |
use IEEE.STD_LOGIC_UNSIGNED.ALL; | |
entity special_counter_tb is | |
end entity; | |
architecture tb of special_counter_tb is | |
component special_counter is |
This file contains hidden or 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
library IEEE; | |
use IEEE.STD_LOGIC_1164.ALL; | |
use IEEE.STD_LOGIC_ARITH.ALL; | |
use IEEE.STD_LOGIC_UNSIGNED.ALL; | |
entity special_counter is | |
port( | |
clk : in std_logic; | |
rst : in std_logic; | |
output : out std_logic_vector(0 to 5) |
This file contains hidden or 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 numpy as np | |
import matplotlib.pyplot as plt | |
from mpl_toolkits import mplot3d | |
from matplotlib.animation import FuncAnimation | |
# Create the figure and the axes | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection = '3d', title = '3D curve animation') | |
# Initialize the axes |