Skip to content

Instantly share code, notes, and snippets.

View amanuel2's full-sized avatar

Aman amanuel2

View GitHub Profile
################################ Robin Karp Rolling Hash (string searching)
class Solution:
# Rabin-Karp algorithm
# In the hashing algo, we can have hash collision and when we have hash collision, 2
# different words can have the same hash. So we need to check that 2 words with same hash
# are really the same to avoid false positive.
# This check frequency can be reduced by taking multiple hashes. In case we take 2 hashes
# the probability of false negatives can go down to 10^-9. So we need to check only once.
# Still the time complexity is O(N + M)
#################################### Union Find
class UnionFind:
def __init__(self, nums):
self.par = {}
self.rank = {}
for num in nums:
self.par[num] = num
self.rank[num] = 1
def find(self, x):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# https://www.interviewbit.com/tutorial/quicksort-algorithm
def binary_search(A, target, start, end):
while(start<=end):
m = (start+end)//2
if(A[m]==target):
return True
elif (A[m] < target):
start = m+1
else:
end = m-1
@amanuel2
amanuel2 / Regex
Created September 12, 2020 02:31
. - Any Character Except New Line
\d - Digit (0-9)
\D - Not a Digit (0-9)
\w - Word Character (a-z, A-Z, 0-9, _)
\W - Not a Word Character
\s - Whitespace (space, tab, newline)
\S - Not Whitespace (space, tab, newline)
\b - Word Boundary
@amanuel2
amanuel2 / index.html
Created August 18, 2020 07:17
Space 404
<div class="moon"></div>
<div class="moon__crater moon__crater1"></div>
<div class="moon__crater moon__crater2"></div>
<div class="moon__crater moon__crater3"></div>
<div class="star star1"></div>
<div class="star star2"></div>
<div class="star star3"></div>
<div class="star star4"></div>
<div class="star star5"></div>
@amanuel2
amanuel2 / index.html
Created August 12, 2020 05:23
Spacy 404 with count up
<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>IMatrix</title>
<link rel="shortcut icon" type="image/x-icon" th-href="${/images/favicon.ico}"/>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"/>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></sc