Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help explain how to solve this. Thank you :) 5. Sloth Sequence (HARD!) A sloth has a sequence of numbers giving the calories obtainable

Please help explain how to solve this. Thank you :)

image text in transcribed

5. Sloth Sequence (HARD!) A sloth has a sequence 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 = si, ..., Sn of numbers, and a number T. You want to find indices f and 2,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, l = 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: .lastIndex(i) returns the smallest index e such that Dj-i si > T, when }=1 $; > T. Returns the value 1 when Ij=1 si

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago