Skip to content

Instantly share code, notes, and snippets.

class TouchedDetector extends StatefulWidget {
final Function(FocusNode, bool) renderer;
const TouchedDetector({Key key, this.renderer}) : super(key: key);
@override
_TouchedDetectorState createState() => _TouchedDetectorState();
}
class _TouchedDetectorState extends State<TouchedDetector> {
import datetime
import math
class Node:
def __init__(self, key, value, weight, lastAccess):
self.key = key
self.value = value
self.weight = weight
self.lastAccess = lastAccess

Question 4 (Optional)

Write a function that takes an array of integers as input. For each integer, output the next fibonacci number. Solution that work both cpu and memory efficient are appreciated.

Fibonacci number of Fn is defined by:
Fn = Fn-1 + Fn-2
F1 = 1, F2 = 1

For example:

Question 3

Please explain what is the bug in the following Javascript function, and how to correct it.

function createArrayOfFunctions(y) {
  var arr = [];
  for (var i = 0; i < y; i++) {
    arr[i] = function(x) {
      return x + i;

Question 2

Design and implement a data structure for cache.

  • get(key) - Get the value of the key if the key exists in the cache, otherwise return -1
  • put(key, value, weight) - Set or insert the value, when the cache reaches its capacity, it should invalidate the least scored key. The scored is calculate as weight / ln(current_time - last_access_time)

Your data structure should be optimized for the computational complexity of get(key) i.e. Average case for computational complexity of get(key) could be O(1).

Question 1

Write a function that takes two arrays as input, each array contains a list of A-Z; Your program should return True if the 2nd array is a subset of 1st array, or False if not.

For example:
isSubset([A,B,C,D,E], [A,E,D]) = true
isSubset([A,B,C,D,E], [A,D,Z]) = false
isSubset([A,D,E], [A,A,D,E]) = true

Please explain the computational complexity of your answer in Big-O notation, i.e. O(log n) or O(n ^2)?

sudo apt-get update
sudo apt install git
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# open new terminal
nvm install --lts
nvm use --lts
import math
corr = df.corr()
corr_abs = corr.abs()
corr_tuples = []
# get highest corr for each col
for (i, col) in enumerate(corr_abs.columns):
corr_with_col = corr_abs.iloc[:, i]\
.sort_values(ascending=False)
# https://stackoverflow.com/questions/17068197/how-to-unzip-the-file-name-csv-gz-files-to-csv
!find . -name '*.csv.gz' -exec gzip -d {} \;
# timeseries data
df[col] = df[col].interpolate
# independent feats, numerical label
df.dropna(how='any', inplace=True)
# categorical feats
groupby_label = df.groupby(label)
print(groupby_label.mean())
print(df.mean())