Skip to content

Instantly share code, notes, and snippets.

View rishi93's full-sized avatar

Rajarishi Devarajan rishi93

View GitHub Profile
@rishi93
rishi93 / test1.py
Last active April 5, 2016 01:17
Supernumbers in a permutation - SUPPER
def lis(arr,n):
dp = [1 for x in range(0,n)]
for i in range(1,n):
for j in range(0,i):
if dp[j] >= dp[i] and arr[j] < arr[i]:
dp[i] += 1
result = []
max_value = max(dp)
i = n-1
while i >= 0:
@rishi93
rishi93 / test1.py
Last active April 7, 2016 05:05
Constructing, Querying and Modifying Segment Tree
from math import log,ceil
arr = [1,3,5,7,9,11]
height = ceil(log(len(arr),2))
tree = [-1 for _ in range(0,2**(height+1))]
def construct(index,start,end):
global tree
if start == end:
tree[index] = arr[start]
@rishi93
rishi93 / test1.cpp
Last active June 9, 2016 17:03
Balanced Brackets using Segment Tree - BRCKTS in C++
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
class Node {
public:
int needLeft;
int needRight;
Node(){
@rishi93
rishi93 / test1.cpp
Created April 4, 2016 10:02
Supernumbers in a permutation - SUPPER using C++
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int maximum(int arr[],int n){
int i,max_val;
max_val = arr[0];
for(i=0; i<n; i++){
if(arr[i] > max_val){
@rishi93
rishi93 / test1.cpp
Last active August 21, 2016 14:48
Dijkstra's Shortest Path - SHPATH using C++
#include <iostream>
#include <map>
#include <vector>
#include <queue>
using namespace std;
class Graph{
public:
vector<pair<int,int> > adjList[10001];
@rishi93
rishi93 / test1.cpp
Created April 6, 2016 07:06
Sorting Bank Accounts - SBANK
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int t,n,testcase;
vector<string> bankList;
string acc,block;
cin>>t;
@rishi93
rishi93 / minheap.py
Last active April 6, 2016 21:59
Implementation of Binary Minimum Heap Tree
class min_heap():
def __init__(self):
self.tree = [-1]
self.length = 0
def insert(self,value):
self.tree.append(value)
print("Inserted",value)
self.length += 1
if self.length == 1:
return
@rishi93
rishi93 / test1.cpp
Created April 7, 2016 06:27
SPOJ GSS1 - solution
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
void construct(int tree[],int arr[],int index,int start,int end){
int mid,max1;
if(start == end){
tree[index] = arr[start];
}
@rishi93
rishi93 / test1.py
Created April 7, 2016 08:47
Binary Search Tree - Python
class node():
def __init__(self,val):
self.left = None
self.right = None
self.value = val
def insert(root,val):
if root is None:
root = node(val)
else:
@rishi93
rishi93 / test1.cpp
Last active June 12, 2016 15:46
SPOJ - AMR11E Solution (Lucky Numbers, with more 3 distinct prime factors)
/* Lucky numbers are numbers with atleast three distinct prime factors
The 1000th lucky number itself lies within 3000
So let's generate primes less than 3000 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;