Problem Brief
The Best Subsequence || Find the minimum of special value of a subsequence
OA
You are given an array arr of size n and an integer k. A subsequence is defined as a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. You need to find a subsequence of size k and calculate its special value.
The special value of a subsequence of size k is defined as:
Summation of absolute difference of consecutive numbers. For i = 2 to k, abs(pi - p(i-1)).
Your task is to find the minimum possible special value among all subsequences of size k in the array.
1Example 1
Input
arr = [9, 5, 1, 4, 9], k = 2
Output
0
Explanation
Subsequence :
{9, 9}2Example 2
Input
arr = [9, 5, 1, 4, 9, 100], k = 3
Output
5
Explanation
Subsequence :
{9, 5, 4}Constraints
Limits and guarantees your solution can rely on.
🌷