Company: UIDAI_16dec
Difficulty: medium
The best subsequence body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; line-height: 1.6; color: #333; max-width: 800px; margin: 20px auto; padding: 0 20px; } h1, h2, h3 { border-bottom: 1px solid #eee; padding-bottom: 10px; } code { background-color: #f4f4f4; padding: 2px 6px; border-radius: 4px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; } pre { background-color: #f4f4f4; padding: 15px; border-radius: 5px; overflow-x: auto; } ul { padding-left: 20px; } The best subsequence Description You are given an array a of size n and an integer k . The special value of a subsequence p is defined as Σ k i=2 |p i - p i-1 |, the sum of absolute differences between consecutive elements of p , where p i denotes the i th element of the subsequence p . Among every subsequence of array a with length exactly k , find the smallest possible s