⭐ 코딩테스트/Codility
[Codility] Abs Distinct
[Codility] Abs Distinct
2024.02.20[Codility] Abs Distinct https://app.codility.com/programmers/lessons/15-caterpillar_method/abs_distinct/start/ Codility Your browser is not supported Please, update your browser or switch to a different one. Learn more about what browsers are supported app.codility.com 해결전략 set 전체 절대값 수 구하기 정답코드 #include #include int solution(vector &A) { set mySet; for(int i = 0; i < A.size(); i++){ mySet.inser..
[Codility] Fib Frog
[Codility] Fib Frog
2024.02.20[Codility] Fib Frog 해결전략 피보나치 Fibonacci 다이나믹 프로그래밍 Dynamic Programming 정답코드 #include #include using namespace std; const int INT_MAX = 2147000000; vector fib; void Fibonacci(int k) { fib.push_back(0); fib.push_back(1); while (fib.back() < k) { fib.push_back(fib.end()[-1] + fib.end()[-2]); } } int solution(vector &A) { int n = A.size(); A.insert(A.begin(), 1); // 개구리가 시작하는 강둑 A.push_back(1); // 개..
[Codility] Count Conforming Bitmasks
[Codility] Count Conforming Bitmasks
2024.02.19[Codility] Count Conforming Bitmasks https://app.codility.com/programmers/trainings/9/count_conforming_bitmasks/start/ Codility Your browser is not supported Please, update your browser or switch to a different one. Learn more about what browsers are supported app.codility.com 해결전략 비트마스크 Bitmask 비트연산자 주어진 정수 A, B, C 중 적어도 하나에 conform하는 다른 정수의 개수를 찾아야 한다. conform이라는 것은? 주어진 정수의 비트 중 하나라도 1이면, con..
[Codility] Disappearing Pairs
[Codility] Disappearing Pairs
2024.02.19[Codility] Disappearing Pairs https://app.codility.com/programmers/trainings/4/disappearing_pairs/start/ Codility Your browser is not supported Please, update your browser or switch to a different one. Learn more about what browsers are supported app.codility.com 해결전략 문자열 String 스택 Stack 처음 시도한 코드 - 시간초과 #include #include using namespace std; string solution(string& S) { int i = 0, j = 1; while ..
[Codility] Binary Gap
[Codility] Binary Gap
2024.02.18[Codility] Binary Gap https://app.codility.com/programmers/trainings/9/binary_gap/start/ Codility Your browser is not supported Please, update your browser or switch to a different one. Learn more about what browsers are supported app.codility.com 해결방안 비트 마스킹 Bitmasking Bitwise operations 정답코드 #include int answer; int solution(int N) { int n = N; int k = 0; while(n){ n /= 2; k++; } int cnt = 0; ..
[Codility] Array Inversion Count
[Codility] Array Inversion Count
2024.02.18[Codility] Array Inversion Count https://app.codility.com/programmers/trainings/4/array_inversion_count/start/ Codility Your browser is not supported Please, update your browser or switch to a different one. Learn more about what browsers are supported app.codility.com 해결전략 정렬 Sorting ※ 중요! QuickSort를 사용하면 안 된다!! 처음 시도한 코드 - 선택 정렬 (시간 초과) #include using namespace std; int solution(vector &A) { i..
[Codility] Tree Height
[Codility] Tree Height
2024.02.18[Codility] Tree Height 해결전략 이진트리 Binary Tree 정답코드 #include int answer; void DFS(tree* node, int currLength) { if(node == nullptr) return; answer = max(answer, currLength); if(node->l != nullptr){ DFS(node->l, currLength + 1); } if(node->r != nullptr){ DFS(node->r, currLength + 1); } } int solution(tree* T) { DFS(T, 0); return answer; } 유사문제 2024.02.18 - [⭐ 코딩테스트/Codility] - [Codility] Tree Longe..
[Codility] Tree Longest Zigzag
[Codility] Tree Longest Zigzag
2024.02.18[Codility] Tree Longest Zigzag https://app.codility.com/programmers/trainings/7/tree_longest_zig_zag/start/ Codility Your browser is not supported Please, update your browser or switch to a different one. Learn more about what browsers are supported app.codility.com 해결전략 이진트리 Binary Tree 정답코드 #include using namespace std; int answer; // Longest Zigzag Length void DFS(tree* node, int currLength, ..
[Codility] The Matrix
[Codility] The Matrix
2024.02.17[Codility] The Matrix https://app.codility.com/programmers/challenges/matrix2021/ The Matrix 2021 challenge Take part in our The Matrix 2021 challenge. app.codility.com 해결전략 이분탐색 정답 코드 #include #include using namespace std; bool Check(vector& A, int k) // Check 함수는 주어진 배열 A에서 k보다 크거나 같은 연속된 숫자의 개수가 k보다 크거나 같은지를 확인하는 함수 { int i = 0; while (i =..
[Codility] FirstUnique
[Codility] FirstUnique
2024.02.07[Codility] FirstUnique https://app.codility.com/programmers/trainings/4/first_unique/start/ Codility Your browser is not supported Please, update your browser or switch to a different one. Learn more about what browsers are supported app.codility.com 해결전략 정렬 sort 정답 코드 #include #include #include int solution(vector &A) { int n = A.size(); queue Q; map myMap; for(int i = 0; i < n; i++){ Q.push(A[..
[Codility] MaxNonoverlappingSegments
[Codility] MaxNonoverlappingSegments
2024.02.06[Codility] MaxNonoverlappingSegments https://app.codility.com/programmers/lessons/16-greedy_algorithms/ 16. Greedy algorithms lesson - Learn to Code - Codility Tie adjacent ropes to achieve the maximum number of ropes of length >= K. app.codility.com 해결전략 그리디 Greedy A[i]가 cur보다 클 때만 쌍을 선택하므로, 항상 A 벡터의 값이 증가하는 방향으로 요소를 선택한다. 정답코드 #include int solution(vector &A, vector &B) { int n = A.size(); if(..