Dynamic programming Flashcards

1
Q

Longest increasing subsequence

A
  1. each number is longest increasing subsequence of value 1.
  2. So for each index, iterate from the start and keep on check whether any value lesser than the current value
  3. If so, max(dp[prev], maxLen)
  4. Finally update dp[i] = maxLen + 1
  5. maxAnswer = max(maxAnswer, dp[i])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Perfect square

A
  1. Find the square required by doing sqrt(n)
  2. For each index, iterate over each sqr and check if its lesser and equal to the index
  3. If so dp[i] = min(dp[i], dp[i - j*j] + 1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly