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
{"MRData":{"xmlns":"http:\/\/ergast.com\/mrd\/1.4","series":"f1","url":"http://ergast.com/api/f1/2018/circuits.json","limit":"30","offset":"0","total":"21","CircuitTable":{"season":"2018","Circuits":[{"circuitId":"albert_park","url":"http:\/\/en.wikipedia.org\/wiki\/Melbourne_Grand_Prix_Circuit","circuitName":"Albert Park Grand Prix Circuit","Location":{"lat":"-37.8497","long":"144.968","locality":"Melbourne","country":"Australia"}},{"circuitId":"americas","url":"http:\/\/en.wikipedia.org\/wiki\/Circuit_of_the_Americas","circuitName":"Circuit of the Americas","Location":{"lat":"30.1328","long":"-97.6411","locality":"Austin","country":"USA"}},{"circuitId":"bahrain","url":"http:\/\/en.wikipedia.org\/wiki\/Bahrain_International_Circuit","circuitName":"Bahrain International Circuit","Location":{"lat":"26.0325","long":"50.5106","locality":"Sakhir","country":"Bahrain"}},{"circuitId":"BAK","url":"http:\/\/en.wikipedia.org\/wiki\/Baku_City_Circuit","circuitName":"Baku City Circuit","Location":{"lat":"40.3725","long": |
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
package Chapter9; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
public class BooleanExpression { | |
private enum Opertor { | |
AND, OR, XOR | |
} |
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
package Chapter9; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
public class Box { | |
public int w; | |
public int h; | |
public int d; |
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
package Chapter9; | |
import java.util.ArrayList; | |
public class EightQueen { | |
public static final int CHESS_BOARD_LENGTH = 8; | |
public static int count = 0; | |
//Check if the position is valid based on previous assignment of other queens | |
private static boolean isValid(int row, int col, ArrayList<Integer> prevRows) { |
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
package Chapter9; | |
import java.util.ArrayList; | |
public class DenomRepr { | |
public static ArrayList<ArrayList<Integer>> allReprs; | |
public static void findAllReprs(int n) { | |
allReprs = new ArrayList<>(); | |
findAllReprs(n, 25, new ArrayList<Integer>()); |
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
package Chapter9; | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.Random; | |
public class FillScreen { | |
private enum Direction { | |
None, Left, Right, Top, Bottom | |
} |
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
package Chapter9; | |
public class PrintParentheses { | |
public static void print(int pairCount) { | |
printAllValid("", pairCount, pairCount); | |
} | |
private static void printAllValid(String cur, int leftRemain, | |
int rightRemain) { | |
if (leftRemain < 0 || rightRemain < 0 || rightRemain < leftRemain) |
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
package Chapter9; | |
import java.util.ArrayList; | |
public class StringPermutation { | |
public static ArrayList<String> getAllPermutations(String s) { | |
ArrayList<String> permutations = new ArrayList<>(); | |
permutations.add(""); | |
for(int i = 0; i < s.length(); i++) { | |
char c = s.charAt(i); |
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
package Chapter9; | |
import java.util.ArrayList; | |
public class AllSubsets { | |
//Iterative way | |
public static ArrayList<ArrayList<Integer>> getAllSubsets(ArrayList<Integer> set) { | |
ArrayList<ArrayList<Integer>> allSubsets = new ArrayList<ArrayList<Integer>>(); | |
allSubsets.add(new ArrayList<Integer>());//empty set |
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
package Chapter9; | |
public class MagicIndexSearcher { | |
public static int searchMagicIndex(int[] a, int lo, int hi) { | |
if(lo > hi || lo < 0 || hi > a.length - 1) | |
return -1; | |
int mid = hi - (hi - lo) / 2; | |
if(a[mid] == mid) | |
return mid; |
NewerOlder