Skip to content

Instantly share code, notes, and snippets.

View rohithpeddi's full-sized avatar

Rohith Peddi rohithpeddi

View GitHub Profile
@rohithpeddi
rohithpeddi / DpMethods.java
Last active January 9, 2017 19:26
LIS,LCS, Edit Distance, Longest Palinfrom Substring, Kadane's Algorithm, MaxSumNoAdjacents
public class DpMethods{
/**********************************************
LONGEST INCREASING SUBSEQUENCE
**********************************************/
int[] Table = new int[N];
Arrays.fill(Table,1);
for(int i=0; i<N; i++){
for(int j=0; j<i; j++){
if(A[j]<A[i] && Table[i]<Table[j]+1){
@rohithpeddi
rohithpeddi / MathMethods.java
Last active January 9, 2017 19:26
is3multiple, all permutations of a string, Numbers without a digit, day of the week, Binomial Coefficient, Shuffle array, Reservoir Sampling, BitCount, Moore Voting Algorithm
public class MathMethods{
/*********************************************
IS3MULTIPLE -
Checks whether a number is 3 multiple or not
much faster - does bitwise operations as follows:
if number is negative make it positive, if it is 0 return 1
if it is 1 return 0, count number of odd set bits and even set
bits and perform this operation recursively
@rohithpeddi
rohithpeddi / Methods.java
Last active December 19, 2016 09:43
Twopair sum[Fast], Prime Sieve, Binary Search
public class Methods{
/*O(N)- Two pair search in a sorted array
It is much better than heap cration, tree creation.
Does work in place and O(1) extra space
*/
public int twoPairSum(int[] a. int k){
int i=0, j= a.length-1;
@rohithpeddi
rohithpeddi / FastReader.java
Last active December 2, 2016 12:42
Class to read input faster
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}