codility(15)
-
[Codility - Java] 5. Prefix Sums - 4. MinAvgTwoSlice
MinAvgTwoSlice A non-empty array A consisting of N integers is given. A pair of integers (P, Q), such that 0 ≤ P < Q < N, is called a slice of array A (notice that the slice contains at least two elements). The average of a slice (P, Q) is the sum of A[P] + A[P + 1] + ... + A[Q] divided by the length of the slice. To be precise, the average equals (A[P] + A[P + 1] + ... + A[Q]) / (Q − P + 1). Fo..
2023.02.01 -
[Codility - Java] 4. Counting Elements - 1. FrogRiverOne
FrogRiverOne Find the earliest time when a frog can jump to the other side of a river. A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river. You are given an array A consisting of N integers representing the falling lea..
2023.01.31 -
[Codility - Java] 3. Time Complexity - 2. PermMissingElem
PermMissingElem Find the missing element in a given permutation. An array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing. Your goal is to find that missing element. Write a function: class Solution { public int solution(int[] A); } that, given an array A, returns the value of the missing elemen..
2023.01.31 -
[Codility - Java] 3. Time Complexity - 1. FrogJmp
FrogJmp Count minimal number of jumps from position X to Y. A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D. Count the minimal number of jumps that the small frog must perform to reach its target. Write a function: class Solution { public..
2023.01.31 -
[Codility - Java] 2. Array - 1. CyclicRotation
CyclicRotation Rotate an array to the right by a given number of steps. An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the fir..
2023.01.31 -
[Codility - Java] 1. Iterations - 1. Binary Gap
BinaryGap Find longest sequence of zeros in binary representation of an integer. A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains..
2023.01.31