| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- leetcode
- 미드시청
- FIT XR
- 괜찮음
- 잡생각
- 10분
- 스탭퍼
- 3줄정리
- 읽기
- realclass
- 뭐든
- 30분
- 리얼 클래스
- 만화도
- 영어원서읽기
- 프로젝트
- 개발자
- 영어공부
- Problem Solving
- 운동
- English
- 파비최
- 쓰릴오브파이트
- 화상영어
- 매일
- 사이드
- Daily Challenge
- 월간
- Writing
- 링피트
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.06.17 Today's Challenge 본문
https://leetcode.com/problems/make-array-strictly-increasing/
Make Array Strictly Increasing - LeetCode
Can you solve this real interview question? Make Array Strictly Increasing - Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing. In one operation, you can choose two ind
leetcode.com
DP 문제
class Solution:
def makeArrayIncreasing(self, arr1: List[int], arr2: List[int]) -> int:
dp = {}
arr2.sort()
def dfs(i, prev):
if i == len(arr1):
return 0
if (i, prev) in dp:
return dp[(i, prev)]
cost = float('inf')
if arr1[i] > prev:
cost = dfs(i+1, arr1[i])
idx = bisect.bisect_right(arr2, prev)
if idx < len(arr2):
cost = min(cost, 1+dfs(i+1, arr2[idx]))
dp[(i,prev)] = cost
return cost
res = dfs(0, -1)
return res if res < float('inf') else -1반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.06.19 Today's Challenge (0) | 2023.06.19 |
|---|---|
| 2023.06.18 Today's Challenge (0) | 2023.06.18 |
| 2023.06.16 Today's Challenge (0) | 2023.06.16 |
| 2023.06.15 Today's Challenge (0) | 2023.06.15 |
| 2023.06.14 Today's Challenge (0) | 2023.06.14 |
Comments