Skip to content

Instantly share code, notes, and snippets.

class Solution {
public int solution(int N) {
// write your code in Java SE 8
int fac=0;
int count=0;
for(int index=(int)Math.sqrt(N);index>0;index--){
fac=N/index;
if(fac*index==N){count=count+2;
if(fac==index){count-=1;}}
import java.math.BigInteger;
import java.util.Random;
class Solution {
private static final Random rnd = new Random();
public static boolean miller_rabin(BigInteger n) {
for (int repeat = 0; repeat < 20; repeat++) {
BigInteger a;
do {
a = new BigInteger(n.bitLength(), rnd);
} while (a.equals(BigInteger.ZERO));
@stephen-maina
stephen-maina / maxslicesum
Created May 2, 2015 16:54
had to research
public class Solution {
public int solution(int[] A) {
int ans = A[0];
int sum = 0;
for (int i = 0; i < A.length; i++) {
if (sum > 0) {
sum += A[i];
} else {
sum = A[i];
}
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
if(A.length==0){
return 0;
}
int ans=0;
int min=Integer.MAX_VALUE;
import java.util.Stack;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
if(A.length==0){
return -1;
}
Stack<Integer> stack=new Stack<Integer>();
int size=0;
int dominatorIndex=0;
@stephen-maina
stephen-maina / equileader
Last active August 29, 2015 14:19
researched the counting bit online
// you can also use imports, for example:
// import java.util.*;
// you can use System.out.println for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.Stack;
class Solution {
public int solution(int[] A) {
// write your code in Java SE 8
Stack<Integer> stack=new Stack<Integer>();
import java.util.Stack;
class Solution {
public int solution(int[] H) {
// write your code in Java SE 8
Stack<Integer> wall=new Stack<Integer>();
int blocks=0;
for(int index=0;index<H.length;index++){
while(!wall.empty()&&H[index]<wall.peek()){
wall.pop();
if(!wall.empty()&&H[index]>wall.peek()){
@stephen-maina
stephen-maina / Fish codility lesson 5
Created April 18, 2015 20:20
had to research to get the full 100
import java.util.Stack;
class Solution {
public int solution(int[] A, int[] B) {
// write your code in Java SE 8
Stack<Integer> upStack=new Stack<Integer>();
Stack<Integer> downStack=new Stack<Integer>();
for(int index=0;index<A.length;index++){
if(B[index]==0){
while(!downStack.empty()&&downStack.peek()<A[index]){
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{
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()){