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 int getUniqueCount(int[] array){ | |
ArrayList<Integer> arrUnique = new ArrayList<Integer>(); | |
for (int i=0; i < array.length; i++){ | |
if (!arrUnique.contains(array[i]){ | |
arrUnique.add(array[i]); | |
} | |
} | |
return arrUnique.size(); | |
} |
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 int getSumLargestSubset(int[] array){ | |
int sumSoFar = 0; | |
int largestSum = 0; | |
for (int i=0; i < array.length; i++){ | |
sumSoFar = sumSoFar + array[i]; | |
if (sumSoFar < 0){ | |
sumSoFar = 0; | |
} | |
else if (sumSoFar > largestSum){ | |
largestSum = sumSoFar; |
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 int rotatedBinarySearch(int[] array, int n, int low, int high){ | |
if (low > high){ | |
return -1; | |
} | |
int mid = (low + high) / 2; | |
if (array[mid] == n){ | |
return mid; | |
} | |
if (array[low] < array[mid]){ |
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 TreeNode{ | |
public int data; | |
public TreeNode left; | |
public TreeNode right; | |
public TreeNode(int d){ | |
this.data = d; | |
this.left = null; | |
this.right = null; | |
} | |
} |
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 TreeNode{ | |
int data; | |
TreeNode left; | |
TreeNode right; | |
public TreeNode(int d){ | |
data = d; | |
left = null; |
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
/* | |
[(1,4), (-10,0), (2,6), (7,10)] --> [(-10,0), (1,6), (7,10)] | |
[(-1,2), (0,3), (10,20), (-5,5)] --> [(-5,5), (10,20)] | |
*/ | |
import java.lang.Math; | |
import java.util.*; | |
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 Node{ | |
int data; | |
Node next; | |
public Node(int d){ | |
this.data = d. | |
this.next = null; | |
} | |
} | |
public boolean doLinkedListsIntersect(Node root1, Node root2){ |
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
import java.util.*; | |
public class permutations | |
{ | |
public static void main(String[] args) | |
{ | |
String str = new String("abc"); | |
StringBuffer output = new StringBuffer(); | |
boolean used[] = {false, false, false}; |
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 StringLib { | |
public static void combine(String str){ | |
int length=str.length(); | |
StringBuffer output=new StringBuffer(); | |
combination(str,length,output,0); | |
} | |
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
/* | |
Print all subset of a given set which sums up to ZERO | |
{8,3,5,1,-4,-8} | |
so ans will be : {8,-8} | |
{3,5,-8} | |
{3,1,-4} | |
*/ | |
import java.util.*; |