Subsequence of an array - Hard Question - Help
Anonymous User
723

A sequence of numbers is said to be good if it satisfirs the following

  • All elements in the sequence are unique
  • If the minimum elements in sequence is x and the maximum elemnt in the sequence is y, then all the numbers in range [x,y] are present in sequence.

Example

arr = [13, 11, 4, 12, 5, 4]
subseq of length 1 = [13, 11, 4, 12, 5, 4]
subseq of length 2 = [13,12],[11,12],[4,5],[5,4]
subseq of length 3 = [13,11,12]

answer = 6 + 4 + 1 = 11

Returns
An integer of good sequences.

Comments (1)