Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Kane is a Twitter employee and a fitness freak. But, it is tough to say no to the culinary delights of the Twitter chefs.
Kane is a Twitter employee and a fitness freak. But, it is tough to say no to the culinary delights of the Twitter chefs. Twitter chefs also mention the calorie value of a meal they are going to prepare for the coming days in advance. So, Kane came up with a plan to be on fast some days and eat on the other days. When he is on fast, he consumes no calories, but on the day he eats, he consumes the amount of calories mentioned in the chart by the chef. His fitness goal is the total amount of calories intake over a certain days of time, that is , he wants to consume a total of X number of calories EXACTLY. Let's say there is an array of positive integers representing calorie counts for each day, help Kane to decide if it's possible to eat the exact number of calories according to his fitness goal Example - 1: Input calCounts : (2, 9, 5, 1, 6), requiredCals : 12 Calories Output = True Because, he can eat on days - 0,1,3 (2 + 9 +1 = 12) OR he can eat on days - 2,3,4 (5 + 1+ 6) Example - 2: Input = calCounts : {2, 3, 15, 1, 16), requiredCals : 8 Calories Output = False Because, the target of 8 cannot be met by adding any of the subset of the values. Limits : Size of the Array def isPossible(calCounts, requiredCals): if _name_ '_main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') calCounts_count = int(input ().strip()) calCounts = [ for - in range (calCounts count): calCounts item = int (input ().strip()) calCounts.append (calCounts_item) | requiredcals = int(input ().strip()) result = isPossible(calCounts, requiredCals) fptr.write(str (int (result)) + 'In') fptr.close ()
Step by Step Solution
★★★★★
3.51 Rating (158 Votes )
There are 3 Steps involved in it
Step: 1
Python program def isPossiblecalCountsrequiredCals if requiredCals 0 return True if len...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started