Skip to content

Instantly share code, notes, and snippets.

View sakhayadeep's full-sized avatar
😅

Sakhayadeep sakhayadeep

😅
View GitHub Profile
@sakhayadeep
sakhayadeep / lowest_common_ancestor.py
Last active November 9, 2019 06:34
Lowest common ancestor in a tree
class Node:
def __init__(self, val, parent = None):
self.val = val
self.parent = parent
self.left = None
self.right = None
class Tree:
def __init__(self, val_list):
@sakhayadeep
sakhayadeep / maze_solver.py
Created September 20, 2019 18:20
A class to solve a matrix maze. A 0 is wall, and 1 is path. Starting and finishing node is given.
class Maze:
def __init__(self, matrix, start, finish):
self.maze = matrix
self.start = start
self.finish = finish
def UP(self, i, j):
try:
return (self.maze[i-1][j], (i-1, j))
except:
s = input()
s = s + s
x = input()
if(x in s):
count = 0
for i in range(len(x)):
if(x in s[i:i+len(x)]):
print(count, "rotation")
break
else:
@sakhayadeep
sakhayadeep / number_pattern.py
Created August 4, 2019 16:04
horizontal number pyramid pattern
x = int(input())
arr = []
k = 1
for i in range(x):
for j in range(i+1):
arr.append(str(k))
k += 1
print(arr)
t = iter(arr)
arr2 = []
@sakhayadeep
sakhayadeep / validateIndianNumbers.py
Last active December 19, 2018 14:02
Python code for Indian Mobile Number validation
'''
Indian Mobile Number validation criteria:
The Country calling code for india is +91
valid pre-fixes are 0,91,+91 .
All mobile phone numbers are 10 digits long (not including a pre-fix).
The first digit should contain number between 9,8,7 or 6.
Rest of the nine digits can be any number between 0 to 9.
'''