Lesson 5. Perfix Sums - CountDiv #1
1. 문제Write a function: int solution(int A, int B, int K);that, given three integers A, B and KReturns the number of integers within the range [A..B] that are divisible by K, i.e.: { i : A ≤ i ≤ B, i mod K = 0 }For example,for A = 6, B = 11 and K = 2, your function should return 3.Because there are three numbers divisible by 2 within the range [6..11], namely 6, 8 and 10.Write an efficient algor..
Lesson 4. Counting Elements - MissingInteger
1. 문제Write a function: int solution(vector &A);that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.Given A = [1, 2, 3], the function should return 4.Given A = [−1, −3], the function should return 1.Write an efficient algorithm for the following assumptions: ..
Lesson 4. Counting Elements - MaxCounters #2 (속도 개선)
1. 이전 코드 분석 (MaxCounters #1)MaxCounters #1에서는,(N + 1)을 만났을 때, 그 즉시 모든 요소를 업데이트 했다.이럴경우, 이중 반복문을 사용하는 것과 같다. 2. 속도 개선 아이디어(N + 1)을 만났을 때, 수행해야할 업데이트 작업을 별도로 분리한다. (나중에 수행한다) 예) N = 5vector ARESULT비고A[0] = 3(0, 0, 1, 0, 0) A[1] = 4(0, 0, 1, 1, 0) A[2] = 4(0, 0, 1, 2, 0) A[3] = 6(0, 0, 1, 2, 0)max_value = 2A[4] = 1(3, 0, 1, 2, 0)max_value + 1 A[5] = 4(3, 0, 1, 3, 0)RESULT[4] + 1A[6] = 4(3, 0, 1, 4..