no image
백준 1629번 문제 풀이(python)
접근A, B, C 모두 32비트 int 범위(약 21억)까지 표현할 수 있다. 문제를 그대로 접근해 보면,X = (A ** B) % C1. A를 21억 번 곱해야 하므로 시간복잡도가 안된다.2. 21억의 거듭제곱 과정에 오버플로우가 고려된다. 풀이해결해 보자.1. (지수 법칙 활용) 지수를 쪼개 시행 횟수를 줄인다.A**30 = (A**15)**2A**15 = (A**7)**2 * AA**7 = (A**3)**2 * AA**3 = (A**1)**2 * AA**1 = A 보통 매 단계마다 값이 절반으로 줄어들 때,마지막까지 도달하는 데 필요한 시행 횟수는 로그 시간 복잡도 O(log N)로 표현한다.100 → 50 → 25 → 12 → 6 → 3 → 1log₂100 ≈ 6.64 1까지 내려가는 각 단계마다..
2025.08.25
no image
스트라센 알고리즘(Strassen Algorithm) - 행렬곱
기본 행렬곱// pseudocode(의사코드)for i from 1 to n: // A의 행(1부터 n까지) for j from 1 to n: // B의 열(1부터 n까지) C[i][j] = 0 // C의 각 원소 초기화 for k from 1 to n: // A의 열과 B의 행(k는 1부터 n까지) C[i][j] = C[i][j] + A[i][k] * B[k][j] end for end for end for행렬곱의 기본 연산은 중첩문이 3개로 O(n^3) 시간복잡도가 필요하다. 스트라센(Strassen) 행..
2025.03.02
no image
Sorting Algorithm
Sorting algorithm 모음Insertion Sort (삽입 정렬)의사 코드 구현 코드public class InsertionSort { static void insertionSort(int[] input) { int count = 0; // 반복 도는 횟수 확인 for (int j = 1; j -1 && input[i] > key) { count++; input[i + 1] = input[i]; i -= 1; } input[i + 1] = key; } System.out.println(count); } pub..
2025.02.24
no image
LeetCode Top Interview Questions - easy collection
https://leetcode.com/explore/interview/card/top-interview-questions-easy/leetcode top interview questions - easy collection을 풀면서 기록ArrayRotate Imagehttps://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/770/ in-place, which means you have to modify the input 2D matrix directly. Do NOT allocate another 2D matrix and do the rotation.in-place algorithm은 input data structu..
2025.02.16
no image
프로그래머스 21kakao_blind 순위검색(python)
https://school.programmers.co.kr/learn/courses/30/lessons/72412 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr from bisect import bisect_left def solution(info, query): a = {"java":"0", "cpp":"1", "python":"2"} b = {"backend":"0", "frontend":"1"} c = {"junior":"0", "senior":"1"} d = {"chicken":"0", "pizza":"1"} results = [] for i in..
2024.03.28
no image
릿코드 2. Add Two Numbers, 49. Group Anagrams
문제 2. https://leetcode.com/problems/add-two-numbers/description/?envType=study-plan-v2&envId=top-interview-150 LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 접근 문제에서 제시한 singly-linked list 구조에 맞춰 알고리즘을 풀어나가는 문제였다. 처음에 순서를 ..
2024.02.17
no image
릿코드 134. Gas Station, 135. Candy
문제 134. https://leetcode.com/problems/gas-station/description/?envType=study-plan-v2&envId=top-interview-150 LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 135. https://leetcode.com/problems/candy/description/?envType=stud..
2024.02.09
no image
릿코드 238. Product of Array Except Self
문제 https://leetcode.com/problems/product-of-array-except-self/description/?envType=study-plan-v2&envId=top-interview-150 LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 접근 나누기를 하지 않고 O(n) 연산을 하라는 것에 아이디어가 안떠올랐다. Discussion ..
2024.02.06
no image
릿코드 45. Jump Game II
문제 링크 https://leetcode.com/problems/jump-game-ii/description/?envType=study-plan-v2&envId=top-interview-150 LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 접근 $ \bullet $ 마지막 인덱스에 도달할 수 없는 case는 없다. $ \bullet $ 그래서, (마지막 인덱..
2024.02.04