An algorithm that turns an integer into binary and returns the biggest amount of zeros in the ranges which are between the character “1” of it.

import java.util.*;

class Algorithm {

    public int[] algorithm(int Num) {
                        .toBinaryString(Num) // turn to binary
                        .replaceAll("(^0+|0+$)", "") // remove the requences which are not between the caracter
                        .split("1")) // create a array where each value is the zeros sequences
                .map(String::length)  // create a map with the length of each sequence
                .reduce(0, Integer::max); // return the max value found


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s