#3409

Longest Subsequence With Decreasing Adjacent Difference

expert · 1215 · lc medium +32 · 16.6% accepted · 150 likes · top 1%

Description

You are given an integer array nums.

Find the length of the longest subsequence seq of nums such that the absolute differences between consecutive elements form a non-increasing sequence. Formally, for a subsequence seq0, seq1, ..., seqm, we require |seq1 - seq0| >= |seq2 - seq1| >= ... >= |seqm - seqm-1|.

Return the length of such a subsequence.

Code

1
2
3