DEV Community

Durga Pokharel
Durga Pokharel

Posted on • Edited on

3

Day 55 Of 100DaysCode : More About Algorithm

Today is my day 55th of 100daysofcode and python learning. Like today I also continue to learned properties of SQL from datacamp.
Like ORDER BY, GROUP BY, HAVING, etc. Also learned more about algorithm from Coursera.

Python Code

Code to calculate maximum pairwise product.

def max_pairwise_product(numbers):
    n = len(numbers)
    max_product = 0
    for first in range(n):
        for second in range(first+1,n):
            max_product = max(max_product, numbers[first] * numbers[second])
    return max_product

input_n = int(input())
input_numbers = [int(x) for x in input().split()]
print(max_pairwise_product(input_numbers))
Enter fullscreen mode Exit fullscreen mode

Output of the following code is,

3
5 6 9
54

Enter fullscreen mode Exit fullscreen mode

Day 55 Of #100DaysOfCode and #Python
* More Properties Of SQL
* More About Algorithm
* Greedy Algorithm
* Code To Calculate Maximum Pairwise Product#womenintech #DEVCommunity #CodeNewbies pic.twitter.com/PkImUnmSpd

— Durga Pokharel (@mathdurga) February 21, 2021

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (2)

Collapse
 
otumianempire profile image
Michael Otu
input_n = int(input())
input_numbers = [int(x) for x in input().split()]
Enter fullscreen mode Exit fullscreen mode
  • input_n was not used.
  • [int(x) for x in input().split()] is the same as list(map(int, input().split()))

To make use of input_n you would have to modify def max_pairwise_product(numbers): to add another parameter, say n as def max_pairwise_product(numbers, n): so that in the function body you'd remove n = len(numbers).

So you would add another parameter, n and remove the line, n = len(numbers)

Collapse
 
iamdurga profile image
Durga Pokharel

Yes. Thank you for the suggestion.

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay