Forget the exact description of the question, but the idea is as below.
Q1:
Given an array, design a function to check whether there is a triple where each element is double of the previous one and in ascending order.
Value can be duplicate.
Values are always positive and greater than zero.
array = [1, 2, 2, 1, 4]
return true
array = [2, 1, 4]
return false
arrray = [4, 2, 1]
return falseQ2: (Follow-up question)
Design another function to return the number of triples where each element is double of the previous one and in ascending order.
array = [1, 2, 2, 1, 4]
return 2, since [1, 2(idx:1), 4] & [1, 2(idx:2), 4] fit. [2, 1 ,4] is not a case.
arrray = [4, 2, 1]
return 0