Longest Increasing Subsequence

Find the length of the longest increasing subsequence in an array using dynamic programming.

Code

Algorithms
dp = Array.new(arr.length, 1)
(1...arr.length).each do |i|
  (0...i).each do |j|
    dp[i] = [dp[i], dp[j] + 1].max if arr[i] > arr[j]
  end
end
return dp.max

Parameters

Array of numbers

Server

More Ruby Snippets