Question: 5. Sloth Sequence (HARD!) A sloth has a sequence S of numbers giving the calories obtainable by hunting on each day. The sloth must obtain

 5. Sloth Sequence (HARD!) A sloth has a sequence S of

5. Sloth Sequence (HARD!) A sloth has a sequence S of numbers giving the calories obtainable by hunting on each day. The sloth must obtain at least T calories total, but wants to find a smallest sequence of contiguous days to do this. Formally, you are given a sequence S = $1,..., Sn of numbers, and a number T. You want to find indices f and l, 1 T, and l - f is as small as possible. If the numbers in the sequence sum to less than T, then you will return NIL. For example if T = 8, and S = 2,4, 1,6, 0, 4, 5, 2, 3, 4, then the answer should be the sequence 4,5 (f = 6, 1 = 7) since this gives the shortest contiguous sequence with value at least T. You want to solve this problem in o(n?) time. You will use 2 functions, defined as follows: lastInder(i) returns the smallest index r such that Di Si > T, when Lj si > T. Returns the value 1 when L315; T, and l - f is as small as possible. If the numbers in the sequence sum to less than T, then you will return NIL. For example if T = 8, and S = 2,4, 1,6, 0, 4, 5, 2, 3, 4, then the answer should be the sequence 4,5 (f = 6, 1 = 7) since this gives the shortest contiguous sequence with value at least T. You want to solve this problem in o(n?) time. You will use 2 functions, defined as follows: lastInder(i) returns the smallest index r such that Di Si > T, when Lj si > T. Returns the value 1 when L315;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!