[코딜리티] codility lesson 9 Maximum slice problem - MaxDoubleSliceSum 100%

문제 요약. https://app.codility.com/programmers/lessons/9-maximum_slice_problem/max_double_slice_sum/ 배열을 세번 잘라내어 더했을 때 가장 높은 값을 찾으시오. 원문. A non-empty zero-indexed array A consisting of N integers is given. A triplet (X, Y, Z), such that 0 ≤ X < Y < Z < N, is called a  double slice . The  sum  of double slice (X, Y, Z) is the total of A[X + 1] + A[X + 2] + ... + A[Y − 1] + A[Y + 1] + A[Y + 2] + ... + A[Z − 1]. For example, array A such that: A[0] = 3 A[1] = 2 A[2] = 6 A[3] = -1 A[4] = 4 A[5] = 5 A[6] = -1 A[7] = 2 contains the following example double slices: double slice (0, 3, 6), sum is 2 + 6 + 4 + 5 = 17, double slice (0, 3, 7), sum is 2 + 6 + 4 + 5 − 1 = 16, double slice (3, 4, 5), sum is 0. The goal is to find the maximal sum of any double slice. Write a function: int solution(int A[], int N); that, given a non-empty zero-indexed array A consisting of N integers, returns the maximal sum of any double slice. Fo

[코딜리티] codility lesson 8 Leader - Dominator 100%

그 동안의 설명이 너무 성의 없는 거 같아 좀더 자세히 써보기로 했습니다. 문제 요약. https://app.codility.com/programmers/lessons/8-leader/dominator/ 배열에서 절반이상을 차지한 값의 인덱스를 찾으세요. 원문. A zero-indexed array A consisting of N integers is given. The  dominator  of array A is the value that occurs in more than half of the elements of A. For example, consider array A such that A[0] = 3 A[1] = 4 A[2] = 3 A[3] = 2 A[4] = 3 A[5] = -1 A[6] = 3 A[7] = 3 The dominator of A is 3 because it occurs in 5 out of 8 elements of A (namely in those with indices 0, 2, 4, 6 and 7) and 5 is more than a half of 8. Write a function int solution(int A[], int N); that, given a zero-indexed array A consisting of N integers, returns index of any element of array A in which the dominator of A occurs. The function should return −1 if array A does not have a dominator. Assume that: N is an integer within the range [ 0 .. 100,000 ]; each element of array A is an integer within the range [ −2,147,483,648 .. 2,1

[코딜리티] codility lesson 7 Stacks and Queues - StoneWall 100%

이미지
문제. Programming language:                   C                          C++                          C#                          Go                          Java                          JavaScript                          Lua                          Objective-C                          Pascal                          PHP                          Perl                          Python                          Ruby                          Scala                          Swift 2                          Swift 3                          VB.NET                      You are going to build a stone wall. The wall should be straight and N meters long, and its thickness should be constant; however, it should have different heights in different places. The height of the wall is specified by a zero-indexed array H of N positive integers. H[I] is the height of the wall from I to I+1 meters to the right of its left end. In particular, H[0] is the height of the wall's left end and H[N−1] i