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 Triangle { | |
// A triplet (P, Q, R) is triangular if 0 ≤ P < Q < R < N and: | |
// | |
// A[P] + A[Q] > A[R], | |
// A[Q] + A[R] > A[P], | |
// A[R] + A[P] > A[Q]. | |
public int hasTriangle(int[] A) { |
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 Distinct { | |
public int distinctElements(int[] A) { | |
if(A == null || A.length == 0) { | |
return 0; | |
} | |
Arrays.sort(A); | |
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 MaxProductOfThree { | |
public int solution(int[] A) { | |
if(A == null || A.length < 3) { | |
return 0; | |
} | |
Arrays.sort(A); | |
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.Stack; | |
public class Fish { | |
public int solution(int[] A, int[] B) { | |
if(A == null || B == null || A.length != B.length) { | |
return -1; | |
} | |
Stack<Integer> downstream = new Stack<>(); | |
int alive = 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
package stacksandqueues; | |
import java.util.Stack; | |
public class Brackets { | |
public int solution(String S) { | |
if(!S.isEmpty() && S.length() % 2 != 0) { | |
return 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
import java.util.Stack; | |
public class EquiLeader { | |
public int solution(int[] A) { | |
if(A == null || A.length == 0) { | |
return 0; | |
} | |
Stack<Integer> stack = new Stack<>(); | |
for(int i = 0; i < A.length; 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 leader; | |
import java.util.Stack; | |
public class Dominator { | |
public int solution(int[] A) { | |
if(A == null || A.length == 0) { | |
return -1; | |
} | |
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 MaxProfit { | |
public int solution(int[] A) { | |
if(A == null || A.length < 2) { | |
return 0; | |
} | |
int maxProfit = 0; | |
int min = -1; | |
for(int i = 0; i < A.length; 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
public class MaxSliceSum { | |
public int maxSliceSum(int[] A) { | |
if(A == null || A.length == 0) { | |
return 0; | |
} | |
int maxSum = Integer.MIN_VALUE; | |
int tempMaxSum = 0; | |
for(int i = 0; i < A.length; i++) { | |
tempMaxSum = Math.max(A[i], A[i] + tempMaxSum); |
OlderNewer