Skip to content

Instantly share code, notes, and snippets.

View tomkaith13's full-sized avatar
🚀

Bibin Thomas tomkaith13

🚀
  • Toronto CA
View GitHub Profile
@tomkaith13
tomkaith13 / palantir.py
Last active August 29, 2015 14:02
palantir question - create a tree out of tuples with 2 elements ( data, depth)
'''
Create a tree out of a list of tuples - (data,depth)
Constraint: The new level node should be added to the latest of the old level node
ex:
if the tuple is:
(a,1)
(b,2)
(c,2)
(d,3)
(e,2)
@tomkaith13
tomkaith13 / random_LSFR.cpp
Created May 30, 2014 06:45
Linear Feedback Shift Register Based uniform random number generator ... it generates 2**32 -1 random numbers
#include<iostream>
using namespace std;
int rand_gen(unsigned int x) {
/*
XOR Linear feedback shift register based random gen
*/
unsigned int a=1;
@tomkaith13
tomkaith13 / profit.py
Created May 17, 2014 03:49
leetcode Best Time to Buy and Sell Stock II
class Solution:
# @param prices, a list of integer
# @return an integer
def addr(self,x,y):
return (x + y)
def maxProfit(self, prices):
if not prices:
return 0
@tomkaith13
tomkaith13 / sametree.py
Last active August 29, 2015 14:01
leetcode- same tree problem
'''
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
'''
# Definition for a binary tree node
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
@tomkaith13
tomkaith13 / singlenum.py
Created May 17, 2014 03:45
leetcode - single number
'''
Given an array of integers, every element appears twice except for one. Find that single one.
'''
class Solution:
# @param A, a list of integer
# @return an integer
def singleNumber(self, A):
A.sort()
@tomkaith13
tomkaith13 / codeeval-125.py
Created May 17, 2014 03:13
predict the number in a sequence of 3 billion
'''
Sequence 011212201220200112 ... constructed as follows: first is 0, then repeated the following action: already written part is attributed to the right with replacement 0 to 1, 1 to 2, 2 to 0. E.g.
0 -> 01 -> 0112 -> 01121220 -> ...
Create an algorithm which determines what number is on the N-th position in the sequence.
INPUT SAMPLE:
Your program should accept as its first argument a path to a filename. Each line in this file contains an integer N such as
0 <= N <= 3000000000. E.g.
"""
Problem:
PASS TRIANGLE
CHALLENGE DESCRIPTION:
By starting at the top of the triangle and moving to adjacent numbers on the row below, the maximum total from top to bottom is 27.
5
9 6