Skip to content

Instantly share code, notes, and snippets.

View anilpai's full-sized avatar
:octocat:
Coding

Anil Pai anilpai

:octocat:
Coding
View GitHub Profile
@anilpai
anilpai / isValidBST.py
Created February 6, 2020 19:57
Check if given Binary Tree is Binary Search Tree (BST) or not.
class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def __str__(self):
return "(%s)"% (self.value)
@anilpai
anilpai / clone_graph_2.py
Created February 3, 2020 23:13
algo to clone a graph
class TreeNode:
""" TreeNode has a value with 3 pointers """
def __init__(self, value, left=None, right=None, random=None):
self.value = value
self.left = left
self.right = right
self.random = random
def __str__(self):
@anilpai
anilpai / clone_graph.py
Created February 3, 2020 22:33
algo to clone a graph
class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_a_tree():
root = TreeNode(10)
a = TreeNode(20)
class TreeNode:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def build_a_tree():
root = TreeNode(10)
a = TreeNode(20)
class LNode:
"""defining a linked list node"""
def __init__(self, value,next=None, random=None):
self.value = value
self.random = random
self.next = next
def __str__(self):
return "(%s)"%(self.value)
@anilpai
anilpai / currency_arbitrage.py
Created September 18, 2019 06:33
Currency Arbitrage using Bellman Ford Algorithm
from typing import Tuple, List
from math import log
rates = [
[1, 0.23, 0.25, 16.43, 18.21, 4.94],
[4.34, 1, 1.11, 71.40, 79.09, 21.44],
[3.93, 0.90, 1, 64.52, 71.48, 19.37],
[0.061, 0.014, 0.015, 1, 1.11, 0.30],
[0.055, 0.013, 0.014, 0.90, 1, 0.27],
[0.20, 0.047, 0.052, 3.33, 3.69, 1],
@anilpai
anilpai / currency_arbitrage.py
Created June 3, 2019 17:12
Currency Arbitrage using Bellman Ford Algorithm
from typing import Tuple, List
from math import log
rates = [
[1, 0.23, 0.26, 17.41],
[4.31, 1, 1.14, 75.01],
[3.79, 0.88, 1, 65.93],
[0.057, 0.013, 0.015, 1],
]
@anilpai
anilpai / gist:9011555223031e837bc45946d22054c2
Created November 1, 2018 16:00
To create a python distribution
python3 setup.py sdist upload -r pypi
@anilpai
anilpai / README.md
Last active June 29, 2018 07:08
Which Emoji to Use? ❓

Commit Type Emoji Initial Commit 🎉 Party Popper Version Tag 🔖 Bookmark New Feature ✨ Sparkles Bugfix 🐛 Bug Security Fix 🔒 Lock Metadata 📇 Card Index Refactoring ♻️ Black Universal Recycling Symbol Documentation 📚 Books Internationalization 🌐 Globe With Meridians

@anilpai
anilpai / 01_Google_Code_Jam_2018.py
Created April 10, 2018 03:31
Saving the Universe Again
def min_hacks(d, p):
p_list = list(p)
can_swap = True
curr_damage, num_of_hacks = (0,)*2
while can_swap:
curr_damage, shoot_damage = 0, 1
for c in p_list:
if c == 'S':
curr_damage += shoot_damage