This file contains 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.ArrayList; | |
public class LongLimitedSubstring{ | |
public static void main(String[] args){ | |
LongLimitedSubstring t = new LongLimitedSubstring(); | |
This file contains 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.Arrays; | |
public class SwapWithZero{ | |
public static void main(String[] args){ | |
SwapWithZero t = new SwapWithZero(); | |
int[] x ={1,0,2,3}; |
This file contains 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 BSTCeiling{ | |
public static void main(String[] args){ | |
BSTceiling t = new BSTceiling(); | |
Node a = t.new Node(3); | |
Node b = t.new Node(1); | |
Node c = t.new Node(6); |
This file contains 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.HashMap; | |
public class AnagramChecker{ | |
public static void main(String[] args){ |
This file contains 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 Rotate{ | |
public static void main(String[] args){ | |
Rotate t = new Rotate(); | |
// 1,2,3 --> 7,4,1 | |
// 4,5,6 --> 8,5,2 | |
// 7,8,9 --> 9,6,3 |
This file contains 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.HashSet; | |
import java.util.Iterator; | |
public class PairFinder{ | |
public static void main(String[] args){ |
This file contains 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.ArrayList; | |
public class MaxHeight{ | |
public static void main(String[] args){ | |
MaxHeight t = new MaxHeight(); | |
This file contains 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.ArrayList; | |
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Set; | |
public class Prover{ | |
This file contains 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
/* | |
* this method takes as input an unsorted list of numbers and returns the largest continious interval of numbers that appeared in the array. | |
* by being clever with a hashSet, you can do this in O(n) time with O(n) memory. of course, if memory were more a concern, you could just sort | |
* it in place, and then walk through (making it O(n lg n)) time and O(1) memory). | |
* The idea is to take an element from the list, and walk backwards and forwards removing those elements from the set. if you ever dont see an | |
* element, stop walking that direction, and then check whether the current distance of your walk is longer than before. | |
* @param int[] x: the list of unsorted numbers | |
*/ | |
public void fastLargestInterval(int[] x){ | |
if (x == null || x.length==0) |
This file contains 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
/* | |
* given a list of numbers, select the Kth number. This means you can select the median, or smallest, or largest, or 10th largest, etc number from your list. | |
* This method uses in place sorting similar to in place quicksort. Because of this, its extra memory is done in O(1) time. AND because each time we go through the | |
* list we eliminate (on average) half the list, its expected time is O(n). however, if the pivot selected is always the max or min, you can have a worst case of | |
* O(n^2). | |
* @return int the kth value from the list you pass in | |
* @param int[] x: a list of numbers | |
* @param k: the kth element you want, can be median, biggest, smallest, etc. make sure k<x.length == true | |
*/ | |
public int selectKth(int[] x, int k){ |
NewerOlder