This is my task2 challenge. I’ve tried to solve this question, but my result wasn’t good. Although there was no error after testing, I only got 33% score.😰
The summary of question shows as below:
I was given a non-empty unsorted array such as: A = [6, 10, 6, 9, 7, 8]. The amplitude of a subsequence of array A is the difference between the largest and the smallest element in this subsequence. The amplitude of the empty subsequence is assumed to be 0.
These are some of the subsequences of array A and their amplitudes:
[6, 6, 7] has amplitude 1;
[6, 10, 6, 9, 7, 8] has amplitude 4;
[6, 6, 7, 8] has amplitude 2.
If this subsequence of array is called quasi-constant, it means its amplitude does not exceed 1. In the example above, subsequence [6, 6, 7] is the longest possible quasi-constant subsequence of array A.
Now, you are expected to provide a method that takes in an array and returns the maximum number of quasi-constant subsequence of array. In above example, the function should return 3.
閱讀更多How to find the longest possible quasi-constant subsequence of array?
(Visited 6,698 times, 1 visits today)