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 com.google.common.collect.Lists; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class SearchInList { | |
public static final ArrayList<List<String>> LIST = Lists.newArrayList( | |
Lists.newArrayList("a", "b"), | |
Lists.newArrayList("c", "d"), |
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.LinkedList; | |
public class DepthSearch { | |
private static final String START = "B"; | |
private static final String END = "E"; | |
public static void main(String[] args) { | |
// this graph is directional | |
Graph graph = new Graph(); |
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.ArrayList; | |
import java.util.List; | |
public class TravelCost { | |
private final static Integer[][] participants = {{500, 700}, {200, 600}, {400, 500}, {600, 200}, {500,300}}; | |
private final static int cityAmount = participants[0].length; | |
private final static List<Integer> result = new ArrayList<>(); | |
public static void main(String[] args) { |
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.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
public class NoRepeating { | |
public static void main(String[] args) { | |
System.out.println(find(null)); | |
System.out.println(find("")); | |
System.out.println(find("111111")); |
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
class Solution { | |
public int solution(int N) { | |
int current = N; | |
int max = 0; | |
int currentGap = 0; | |
boolean start = false; | |
while (current / 2 != 0) { | |
if (current % 2 != 0) { | |
max = currentGap > max ? currentGap : max; | |
currentGap = 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
class Solution { | |
public int solution(int[] A) { | |
int sum = 0; | |
int diff = Integer.MAX_VALUE; | |
for (int i : A) { | |
sum += i; | |
} | |
for (int i = A.length -1; i > 0; i--) { | |
sum -= 2 * A[i]; | |
int abs = Math.abs(sum); |
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
class Solution { | |
public int solution(int[] A) { | |
int sum = 0; | |
int sumA = 0; | |
for (int i = 0; i < A.length; i++) { | |
int digit = i + 1; | |
sum += digit; | |
sumA += A[i]; | |
} | |
return A.length + 1 - (sumA - sum); |
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
class Solution { | |
public int[] solution(int N, int[] A) { | |
int[] result = new int[N]; | |
int currentMax = 0; | |
int max = 0; | |
for (int i: A) { | |
if (i == N + 1) { | |
max = currentMax; | |
} else { | |
int digit = result[i-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
// you can also use imports, for example: | |
import java.util.Map; | |
import java.util.HashMap; | |
// you can write to stdout for debugging purposes, e.g. | |
// System.out.println("this is a debug message"); | |
class Solution { | |
public int[] solution(String S, int[] P, int[] Q) { | |
Map<String, Integer> mapping = new HashMap<>(); |
OlderNewer