환영합니다. 이 블로그 번째 방문자입니다.
[Q3:English] Kth largest element
Given an array of integers arr and an integer k find the kth largest element. (1 ≤ k ≤ length of arr) For example, arr = [4,2,9,7,5,6,7,1,3], k = 4, output : 6. [ Method 1] # Logic Remove max element in the arr for k-1 times and return max element. # Code # Complexity T(n,k) : (k-1) * 2n + n = O(kn) S(n) : O(1) [Method 2] # Logic Use sorting # Code # Complexity T(n,k) : O(nlogn) + O(1) = O(nlogn..
[Q2:English] First and last index in sorted array
👇🏻 문제(이 정도는 해석X...귀찮,, 영어강의라 포스트도 영어로) Given a sorted array of integers arr and an integer target, find the index of the first and last position of target in arr. In targer can't be found in arr, return [-1,-1]. For example, arr = [2,4,5,5,5,5,5,7,9,9], target = 5 👉🏻 output : [2, 6] [Method 1] # Logic # Code # Complexity S(n) = O(1) T(n) = O(n) [Method 2] How about using binary search? Because i..