본문 바로가기

공부하자/Codility

(35)
[Codility] Lesson5. CountDiv (C#) 문제: app.codility.com/programmers/lessons/5-prefix_sums/count_div/ CountDiv coding task - Learn to Code - Codility Compute number of integers divisible by k in range [a..b]. app.codility.com double a = (double)A; double b = (double)B; double result = 0; //for(int i = A; i
[Codility] Lesson4. PermCheck (C#) 문제: app.codility.com/programmers/lessons/4-counting_elements/perm_check/ PermCheck coding task - Learn to Code - Codility Check whether array A is a permutation. app.codility.com List ListA = new List(A); ListA.Sort(); int index = ListA.Count; if (index == 0) return 0; for (int i = 0; i < index; i++) { if (ListA[i] != i + 1) return 0; } return 1;
[Codility] Lesson4. MissingInteger (C#) 문제: app.codility.com/programmers/lessons/4-counting_elements/missing_integer/ MissingInteger coding task - Learn to Code - Codility Find the smallest positive integer that does not occur in a given sequence. app.codility.com 66% - 다시 풀어야 함 int result = 1; List ListA = new List(A); ListA.Sort(); int index = ListA.IndexOf(1); if (index > 0) // 음수 지우기 ListA.RemoveRange(0, index - 1); if (ListA.Coun..
[Codility] Lesson4. MaxCounters (C#) 문제: app.codility.com/programmers/lessons/4-counting_elements/max_counters/ MaxCounters coding task - Learn to Code - Codility Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum. app.codility.com 77% (다시 풀어야 함) int[] result = new int[N]; int max = 0; for (int i = 0; i < A.Length; i++) { int position = A[i..
[Codility] Lesson4. FrogRiverOne (C#) 문제: app.codility.com/programmers/lessons/4-counting_elements/frog_river_one/ FrogRiverOne coding task - Learn to Code - Codility Find the earliest time when a frog can jump to the other side of a river. app.codility.com Hashtable all = new Hashtable(); // O(N) //List all = new List(); O(N**2) for (int i = 0; i < A.Length; i++) { if (A[i]
[Codility] Lesson3. TapeEquilibrium (C#) 문제: app.codility.com/programmers/lessons/3-time_complexity/tape_equilibrium/ TapeEquilibrium coding task - Learn to Code - Codility Minimize the value |(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|. app.codility.com if (A.Length >= 2 && A.Length Math.Abs(sum1 - sum2)) result = Math.Abs(sum1 - sum2); } return result; } return 0;
[Codility] Lesson3. PermMissingElem (C#) 문제: app.codility.com/programmers/lessons/3-time_complexity/perm_missing_elem/ PermMissingElem coding task - Learn to Code - Codility Find the missing element in a given permutation. app.codility.com List ListA = new List(A); ListA.Sort(); if (ListA.Count > 0 && ListA.Count
[Codility] Lesson3. FrogJmp (C#) 문제: app.codility.com/programmers/lessons/3-time_complexity/frog_jmp/ FrogJmp coding task - Learn to Code - Codility Count minimal number of jumps from position X to Y. app.codility.com if (X >= 1 && X = 1 && Y = 1 && D