Question: Problem 1 Given a list L of strings, the function should return a list of length 2 containing the longest string followed by the second-longest
Problem 1
Given a list L of strings, the function should return a list of length 2 containing the longest string followed by the second-longest string. You can assume that L contains at least 2 strings. If there are several choices for the longest string, the first of these in L is designated as the longest string. Similarly, if there are several choices for the second longest string, the first of these in L is designated as the second longest string.
Examples: twoLongestStrings(["ok", "hello", "is", "bye"]) returns ["hello", "bye"]
twoLongestStrings(["ok", "is", "bye"]) returns ["bye", "ok"]
twoLongestStrings(["ok", "bed", "bye"]) returns ["bed", "bye"]
Problem 2
Given a list L of n numbers, the list of prefix sums of L is a list of length n, in which the element at index i is the sum of elements at indices O through i in L. For example, if L is[ 3, 1, 4, 7], then the list of prefix sums of L is the list [3, 4, 8, 15].
Your task is to write a function with the following signature: def prefixSumList(L):
Specification: This function should return a list (that has the same length as L) that is the prefix sum list of L. Note that if L is an empty list, the function will also return an empty list. You can assume that L only contains numbers
Examples: prefixSumList ([0, 1, 2, 3, 4]) returns [0, 1, 3, 6, 10]
prefixSumList([1]*5) returns [1, 2, 3, 4, 5]
prefixSumList(1, -1, 1, -1, 1, -1]) returns [1, 0, 1, 0, 1, 0]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
