[Codility] Lesson9. MaxSliceSum (Python)
·
코딩 테스트
1. 문제 https://app.codility.com/c/run/training2B63MW-T7C/ Codility Your browser is not supported You should use a supported browser. Read more app.codility.com 2. 풀이 테스트케이스 1개가 안풀려서 답을 찾아봤던 문제. 이 문제의 해결 포인트는 합이 음수가 나오기 전까지 계속 합을 더해주고, 음수가 나오면 그 다음 수부터 다시 누적합을 구하면된다. 왜냐하면 현재 음수보다 이전의 합이 더 작으면 앞으로 누적합을 더해도 합이 음수이기 때문에 그 만큼 합계가 작아지기 때문이다. 3. 코드 # you can write to stdout for debugging purposes, e.g. ..
[Codility] Lesson8. MaxDoubleSliceSum (Python)
·
코딩 테스트
1. 문제 https://app.codility.com/c/run/training7WK46H-9HS/ Codility Your browser is not supported You should use a supported browser. Read more app.codility.com 2.풀이 처음에 combination으로 만들수있는 인덱스(3개) 조합을 구하고 그 인덱스에 해당하는 합계를 구하니 시간초과가 났다 ㅜ,ㅜ 시간초과 해결 방법이 생각안나서 구글링으로 결국 해결,,, 전형적인 dp 알고리즘을 사용해서 풀어야하는 문제였다. 왼쪽-> 오른쪽 방향으로 배열의 누적 합을 미리 저장했었는데 왼쪽
[Codility] Lesson5. PassingCars (Python)
·
코딩 테스트
1.문제 app.codility.com/demo/results/training7U86YM-SXN/ Test results - Codility A non-empty array A consisting of N integers is given. The consecutive elements of array A represent consecutive cars on a road. Array A contains only 0s and/or 1s: 0 represents a car traveling east, 1 represents a car traveling west. The goal is to count app.codility.com 2.풀이 prefix sum을 응용해서 뒤에서부터 합계를 sum 리스트에 저장했다...
[Codility] Lesson5.MinAvgTwoSlice (Python)
·
코딩 테스트
1. 문제 app.codility.com/c/run/trainingR25CEU-GHW/ Codility Your browser is not supported You should use a supported browser. Read more app.codility.com 2. 풀이 Timeout Error 시간초과 ㅜ__ㅜ 결과적으로 slice 크기가 2 또는 3일 경우에만 비교해야한다. (A+B) res: minval = res answer = p return answer 처음에 작성했던 코드. 시간초과로 Fail # return the smallest starting position of such a slice. # average = sum[P:Q]/(Q-P+1) def solution(A): mina..
[Codility] Lesson8. Dominator
·
코딩 테스트
🔮문제 An 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 o..
[Codility] Lesson4. FrogRiverone (C++)
·
코딩 테스트
🔮문제 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 leaves. A[K] represents the position where one leaf falls at time K, measured in secon..