Skip to content

Instantly share code, notes, and snippets.

@Semant1ka
Semant1ka / solution.py
Last active February 20, 2022 03:11
Maximum hit count in any given window
"""
You are given a set of log files in the format below.
Write a function that will return a resource with maximum number of hits in any 5 minute time frame.
You should return hits count and resource name.
"""
log = [
["2", "user_1", "resource_1"],
["130", "user_1", "resource_1"],
["355", "user_1", "resource_2"],
@Semant1ka
Semant1ka / solution.py
Created January 27, 2022 03:44
426. Convert Binary Search Tree to Sorted Doubly Linked List
"""
# Definition for a Node.
class Node:
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left # prev
self.right = right # next
"""
"""
Approach:
@Semant1ka
Semant1ka / solution.py
Created January 25, 2022 03:35
Interview problem #1
from collections import OrderedDict, defaultdict
def add_tags(obj, string):
# remember the index of each element
indexes = {k: v for k, v in enumerate(string)}
# formatting
formatting = defaultdict(list)
@Semant1ka
Semant1ka / solution.py
Last active January 20, 2022 18:54
588. Design In-Memory File System
from collections import deque
class FileObject:
def __init__(self, name):
self.content = None
self.name = name
self.children = []
class FileSystem:
@Semant1ka
Semant1ka / solution.py
Created January 18, 2022 16:56
362. Design Hit Counter
class HitCounter:
def __init__(self):
self.counters = dict()
def hit(self, timestamp: int) -> None:
self.counters[timestamp] = self.counters.get(timestamp, 0) + 1
@Semant1ka
Semant1ka / solution.py
Created January 18, 2022 02:57
297. Serialize and Deserialize Binary Tree
from collections import deque
class Codec:
def serialize(self, root):
"""Encodes a tree to a single string.
:type root: TreeNode
:rtype: str
"""
sankeyDraw(
{
"nodes": [
{"name": "Improve CX Flow"},
{"name": "Nevermind Response"},
{"name": "Download Resources"},
{"name": "Our Amazing Customers"},
{"name": "Last Response"},
{"name": "Emoji Response"},
{"name": "Greeting"},
@Semant1ka
Semant1ka / index.html
Last active May 14, 2019 17:04 — forked from soxofaan/index.html
d3-plugins sankey cycle support
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript" src="./sankey.js"></script>
<title>Sankey Diagram</title>
<style>
{"nodes": [{"name": "Improve CX Flow"}, {"name": "Nevermind Response"}, {"name": "Download Resources"}, {"name": "Our Amazing Customers"}, {"name": "Last Response"}, {"name": "Emoji Response"}, {"name": "Greeting"}, {"name": "Abandoned"}, {"name": "About Ada"}, {"name": "Customers"}, {"name": "Customer's Bot On Site"}, {"name": "Mike Murchison"}, {"name": "David Hariri"}, {"name": "How much can I save"}, {"name": "Ada in the Press"}, {"name": "Positive Review"}, {"name": "Careers"}, {"name": "Mikael"}, {"name": "1000-5000"}, {"name": "Wolfram Alpha API"}, {"name": "About"}, {"name": "Price"}, {"name": "Channels"}, {"name": "> 5000"}, {"name": "Sad"}, {"name": "Acknowledgement"}, {"name": "No, I'm just browsing"}, {"name": "Wolfram API - II"}, {"name": "Competition"}, {"name": "24/7 Office Hours"}, {"name": "Personalize - Website Landing Page"}, {"name": "Personalize - Customize every convo"}, {"name": "Optimize - Calculate your savings"}, {"name": "Languages"}, {"name": "Self-Learning"}, {"name": "Common Ques
@Semant1ka
Semant1ka / etl_tools.csv
Created April 18, 2019 17:35
ETL tools
Name Price Link Language
Apache Airflow Free (Paid cloud integrations available) https://airflow.apache.org/ Python
Luigi Free https://luigi.readthedocs.io Python
Scriptella Free http://scriptella.org/#usage SQL and JavaScript
Talend Available for free https://www.talend.com/
Matillion Prices from $1.37 per hour https://www.matillion.com/