Algorithmic Toolbox | Week 1

Course Name: Algorithmic Toolbox

Course Link: Algorithmic Toolbox

These are Algorithmic Toolbox Week 1 Programming Assignment Coursera Answers


Programming Assignment: Programming Assignment 1: Sum of Two Digits

1-1: Sum of Two Digits

def sum_of_two_digits(first_digit, second_digit):
    return first_digit + second_digit

if __name__ == '__main__':
    a, b = map(int, input().split())
    print(sum_of_two_digits(a, b))

Programming Assignment: Programming Assignment 1: Maximum Pairwise Product

1-2: Maximum Pairwise Product

def max_pairwise_product(numbers):
    n = len(numbers)
    
    if n < 2:
        return 0

    max1 = max(numbers[0], numbers[1])
    max2 = min(numbers[0], numbers[1])

    for i in range(2, n):
        if numbers[i] > max1:
            max2 = max1
            max1 = numbers[i]
        elif numbers[i] > max2:
            max2 = numbers[i]

    return max1 * max2

if __name__ == '__main__':
    _ = int(input())
    input_numbers = list(map(int, input().split()))
    print( max_pairwise_product( input_numbers))

These are Algorithmic Toolbox Week 1 Programming Assignment Coursera Answers


More Weeks of the course: Click Here

More Coursera courses: https://progiez.com/coursera

Algorithmic Toolbox Week 1 Programming Assignment
See also  Algorithmic Toolbox | Week 2