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
// my solution is based on iterating all the list comparing all possible sums and find the max sum. | |
class Solution { | |
public static int solution(int[] A) { | |
int length = A.length; | |
int max = 0; | |
int sum = 0; | |
for (int x = 0; x < length - 4; x++) { | |
for (int y = x + 2; y < length - 2; y++) { | |
for (int z = y + 2; z < length; z++) { | |
for (int l = x + 1; l <= (y - 1); l++) { |
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
def solution (N, A): | |
counters = [0] * N # number_of_counters | |
for K in A: | |
if 1 <= K <= N: | |
counters[K-1] += 1 | |
elif K > N: | |
max_value = max(counters) | |
for index in range(len(counters)): | |
counters[index] = max_value | |
return counters |
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
// Task is to find out how many jumps is needed to get from distance X to Y. Length of every jump is D. | |
it is one of codility tasks | |
class Solution { | |
// X = beginning, Y = finish, D = distance | |
public int solution(int X, int Y, int D) { | |
int state = X; | |
int count = 0; | |
while (state < Y) { | |
state = state + D; |
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
// find element without pair in array | |
def solution(A): | |
A.sort() | |
for index in range(0,len(A),2): | |
if A[index] != A[index+1]: | |
return A[index] | |
B = [5,6,2,9,2,3,6,7,3,1,7,9,1] | |
print(solution(B)) |
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
// find odd element in array | |
def solution(A): | |
accessed = [False] * len(A) | |
randit = len(A) | |
for a in range(len(A)): | |
if accessed[a] == False: | |
for b in range(len(A)): | |
if a == b: | |
continue | |
if accessed[b] == False: |