Longest Subsequence with difference 1

Revision en1, by 150iq, 2021-04-27 14:05:38

Is it possible to solve this problem in O(n) given that the numbers can only be in the range from 1 to 1000?

P.S: I tried solving this in O(n) but I am getting WA. I also created a random input generator and compared my output with the correct code for n = 100 and values from 1 to 100 but didn't find any difference.

My Code
Tags # dp, #dynamic programing, # 2d dp

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English 150iq 2021-04-27 14:05:38 963 Initial revision (published)