This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class FastReader | |
{ | |
BufferedReader br; | |
StringTokenizer st; | |
public FastReader() | |
{ | |
br = new BufferedReader(new | |
InputStreamReader(System.in)); | |
} |