Skip to content

Instantly share code, notes, and snippets.

View theabbie's full-sized avatar
❤️
Playing With Life Since 2002

Abhishek Choudhary theabbie

❤️
Playing With Life Since 2002
View GitHub Profile
@theabbie
theabbie / RandomGraphGenerator.py
Created January 24, 2024 05:09
Random Graph Generator
from random import *
# Floyd Sampler
def sampler(N, K):
res = set()
for i in range(N - K, N):
j = randint(0, i)
if j not in res:
res.add(j)
else:
@theabbie
theabbie / RandomTreeGenerator.py
Created January 23, 2024 11:02
Random Tree Generator
from random import *
def randTree(N):
edges = []
comps = [[i] for i in range(N)]
for _ in range(N - 1):
i = randint(0, len(comps) - 1)
j = randint(0, len(comps) - 2)
if j == i:
j += 1
@theabbie
theabbie / lights_out.md
Last active October 6, 2023 10:49
Python Script to solve "Lights Out" Game in optimal way using BFS.
@theabbie
theabbie / iterative_merge_sort.py
Created September 6, 2023 09:36
Iterative Merge Sort in Python
def merge(arr, i, mid, j, extra):
x = i
y = mid
while x < mid and y < j:
if arr[x] <= arr[y]:
extra[x + y - mid] = arr[x]
x += 1
else:
extra[x + y - mid] = arr[y]
y += 1
@theabbie
theabbie / leetcode.txt
Created February 21, 2023 12:42
All Leetcode Questions
1 two-sum
2 add-two-numbers
3 longest-substring-without-repeating-characters
4 median-of-two-sorted-arrays
5 longest-palindromic-substring
6 zigzag-conversion
7 reverse-integer
8 string-to-integer-atoi
9 palindrome-number
10 regular-expression-matching
@theabbie
theabbie / ascii_human.py
Last active October 22, 2022 08:12
Dancing ASCII Human in Python
import random
from time import sleep
class Human:
def __init__(self):
self.human = [[" ", "o", " "], ["/", "|", "\\"], ["/", " ", "\\"]]
self.front = False
self.commandmap = {
"left hand to head": self.leftHandToHead,
"left hand to hip": self.leftHandToHip,
@theabbie
theabbie / rle.py
Created October 15, 2022 19:16
Run-length Encoding Imlementation in Python
def encode(s):
n = len(s)
res = []
i = 0
while i < n:
ctr = 1
while i < n - 1 and s[i] == s[i + 1]:
ctr += 1
i += 1
if ctr == 1:
@theabbie
theabbie / binexp.py
Created October 11, 2022 14:27
Iterative binary exponentiation
def pow(a, b):
curr = a
res = 1
while b:
if b & 1:
res *= curr
b = b >> 1
curr *= curr
return res
@theabbie
theabbie / triemap.py
Last active September 22, 2022 04:51
TrieMap implementation in python
class Node:
def __init__(self, val = None):
self.left = None
self.right = None
self.val = val
self.end = False
class TrieMap:
def __init__(self):
self.root = Node()
@theabbie
theabbie / trie.py
Created September 20, 2022 05:46
Trie (Prefix Tree) Implementation in Python
class Node:
def __init__(self):
self.child = {}
self.end = False
class Trie:
def __init__(self):
self.root = Node()
def insert(self, s):