Following examples. [1, 3, 6, 4, 1, 2, 7] then return 5 [-1, 1, 2, 3] the return 4 [−1, … More
Author: camilamacedo86
An algorithm that checks if the values of an array form one or two numerical sequences starting from 1
If the values of the array can form one or two numerical sequences then return 1 otherwise return 0. For example … More
[Utils] – Configuration to show the current git branch on the terminal
Following the result of this setup. To do this setup go to the bash_profile and add the following code. (~/.bash_profile … More
An algorithm to find the min value of the difference between the sum of all numbers from all possible two parts to which it can be divided
The solution is the min absolute value of |(A[0] + … + A[D-1]) – (A[D] + … + A[N-1])| where A … More
An algorithm to find the missing number in a progressive sequence [1 .. (N + 1)]
Solution public int gauss(int[] sequence) { long lastValue = sequence.length + 1; long total = (lastValue * (lastValue + 1)) … More
An algorithm which calculates the minimal quantity of steps to walk from a point to another.
Knowing that A is the starting point B is the destination point D is the step size Assume that A, … More
What is the Big-O?
The big-o notation is a relative representation of the complexity of an algorithm. In simple words, it means that this … More
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) { return Arrays.stream( Integer .toBinaryString(Num) // turn to binary .replaceAll(“(^0+|0+$)”, “”) … More
[Java8] – How to check if all values in an array are equals?
public boolean isAllValuesEquals(int[] Arr ){ if ( Arrays.stream(Arr).distinct().count() == 1 ) { return true; } return false; }
[Java] – How to concatenate two arrays?
public int[] joinArrays(int[] int1, int[] int2) { int[] result = new int[Arr.length]; System.arraycopy( int1, 0, result, 0, int1.length); System.arraycopy( int2, … More