본문 바로가기

프로그래밍/Codility10

MaxCounters 문제 You are given N counters, initially set to 0, and you have two possible operations on them: increase(X) − counter X is increased by 1, max counter − all counters are set to the maximum value of any counter. A non-empty array A of M integers is given. This array represents consecutive operations: if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X), if A[K] = N + 1 then operation .. 2021. 1. 2.
[C#] FrogRiverOne [문제] 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 seco.. 2021. 1. 2.
[C#] codility TapeEquilibrium 문제풀이2 [문제] TapeEquilibrium coding task - Learn to Code - Codility Minimize the value |(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|. app.codility.com 전에 이 문제를 풀었을때는 성능이 진짜 별로였는데, 오늘은 성능. 문제를 해결하기 위해 끙끙 거리다 드뎌 해결했다. [답] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 public int Solution(int[] A) { int result = 0, sum = 0; for(int j = 0; j dif) result = dif;.. 2021. 1. 1.
[c#] Codility - PermCheck A non-empty array A consisting of N integers is given. A permutation is a sequence containing each element from 1 to N once, and only once. For example, array A such that: A[0] = 4 A[1] = 1 A[2] = 3 A[3] = 2 is a permutation, but array A such that: A[0] = 4 A[1] = 1 A[2] = 3 is not a permutation, because value 2 is missing. The goal is to check whether array A is a permutation. Write a function:.. 2019. 9. 3.
[c#] codility - TapeEquilibrium - 좀 더 생가해보기. > 정확도는 100이지만 퍼포먼스는 0인 코드. > 다시 생각해보기. ...더보기 public int Solution(int[] A) { int p = A.Length - 1; int rightN = 0, leftN = 0; int[] right, left; int idx = 1; var minList = new List(); // 정확하지만 퍼포먼스는 0인 코드 //Detected time complexity: //O(N * N) while (idx < A.Length) { leftN = idx; rightN = A.Length - leftN; left = new int[leftN]; right = new int[rightN]; Array.Copy(A, idx, right, 0, A.Length-idx.. 2019. 9. 2.
[c#] Codility - PermMissingElem ...더보기 using System; using System.Linq; // you can also use other imports, for example: // using System.Collections.Generic; // you can write to stdout for debugging purposes, e.g. // Console.WriteLine("this is a debug message"); class Solution { public int solution(int[] A) { var list = A.ToList(); var count = list.Count + 1; long listSum = 0; foreach(var r in list) { listSum = r + listSum; } v.. 2019. 9. 1.
[c#] codility : frogjmp 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 int solution(int X, int Y, int D); } that, given three inte.. 2019. 9. 1.
[c#] Codility - CyclicRotation Task description 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 first place). The goal is to rotate array A K times; that .. 2019. 8. 30.
C# [codility] OddOccurrencesInArray - 둘다 100,100,100 이고 아래의 시간복잡도를 보여줌. - dictionary에는 중복된 키값이 들어갈 수 없음을 이용한 방법 ...더보기 dictionary public int Solustion2(int[] A) { var list = A.ToList(); var dic = new Dictionary(); foreach(var r in list) { if (dic.ContainsKey(r)) dic.Remove(r); else dic.Add(r, r); } return dic.Keys.First(); } ...더보기 xor 연산자 사용 public int Solution3(int[] A) { int temp = 0; var list =.. 2019. 8. 29.
반응형