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.BitSet; | |
import java.util.stream.IntStream; | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
BitSet bs=new BitSet(A.length+1); | |
//IntStream.of(A).filter(p->p==1).forEach(i->bs.set(i)); | |
for(int set=0;set<A.length;set++){ | |
if(A[set]==1){ | |
bs.set(set,true); |
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) { | |
// write your code in Java SE 8 | |
int count=0; | |
int pair=0; | |
for(int index=0;index<A.length;index++){ | |
if(A[index]==0){ | |
count++; | |
}else{ | |
pair+=count; |
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 B, int K) { | |
// write your code in Java SE 8 | |
int first=0; | |
int last=0; | |
if(A%K==0){ | |
first=A/K; | |
}else{ | |
first=(A-A%K+K)/K; | |
} |
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.Arrays; | |
import java.util.HashMap; | |
class Solution { | |
public int[] solution(String S, int[] P, int[] Q) { | |
// write your code in Java SE 8 | |
int []result=new int[P.length]; | |
for(int index=0;index<P.length;index++){ | |
String check= S.substring(P[index],Q[index]+1); | |
if(check.contains("A")){ | |
result[index]=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
import java.util.stream.IntStream; | |
import java.lang.Math; | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
int [] sorted=IntStream.of(A).sorted().toArray(); | |
return Math.max(sorted[0]*sorted[1]*sorted[sorted.length-1],sorted[sorted.length-1]*sorted[sorted.length-2]*sorted[sorted.length-3]); | |
} | |
} |
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.stream.IntStream; | |
import java.util.Set; | |
import java.util.stream.Collectors; | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
Set<Integer> result=IntStream.of(A).boxed().collect(Collectors.toSet()); | |
return result.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
import java.util.stream.IntStream; | |
class Solution { | |
public int solution(int[] A) { | |
// write your code in Java SE 8 | |
int[]sorted=IntStream.of(A).sorted().toArray(); | |
for(int index=2;index<sorted.length;index++){ | |
long ind1=(long)sorted[index]; | |
long ind2=(long)sorted[index-1]; | |
long ind3=(long)sorted[index-2]; | |
if(ind3+ind2>ind1&&ind1+ind2>ind3&&ind3+ind1>ind2){ |
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 result = 0; | |
int[] dps = new int[a.length]; | |
int[] dpe = new int[a.length]; | |
for (int i = 0; i < a.length; i++) | |
{ | |
dps[Math.max(0, i - a[i])]++; | |
dpe[Math.min(a.length - 1, i + a[i])]++; |
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.Stack; | |
class Solution { | |
public int solution(String S) { | |
// write your code in Java SE 8 | |
char [] test= S.toCharArray(); | |
Stack<String> container=new Stack<String>(); | |
for (int index=0;index<test.length;index++){ | |
char popped=test[index]; | |
if(container.empty()){ |
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.Stack; | |
class Solution { | |
public int solution(String S) { | |
// write your code in Java SE 8 | |
Stack<String>stack=new Stack<String>(); | |
for(int index=0;index<S.length();index++){ | |
if(S.charAt(index)=='('){ | |
stack.push("("); | |
}else{ |