Categories
Coding Computer Science Python

Solving Problem: Maximize It!

Refer: Maximize It! | HackerRank

maximize.py
Python
import itertools
def f(x):
return x**2
def maximized(K,M):
S = []
li1 = []
for i in range(K):
inp1 = list(map(int,input().split()))
li = inp1[1:]
li1.append(li)
combinations = list(itertools.product(*li1))
for i in combinations:
Si = sum([f(x) for x in list(i)])%M
S.append(Si)
return max(S)
if __name__== "__main__":
inp = list(map(int,input().split()))
K, M = inp[0], inp[1]
print(maximized(K, M))

All tests passed!

Please feel free to drop any suggestions or input.

Happy coding!!!

Priyanka B.'s avatar

By Priyanka B.

Hello and welcome to my little corner of internet!! I am a techie. I am very interested to discover and innovate new advances in science and technology. Blogging is one of my hobbies which I think is very useful for broadening my knowledge horizons and help me grow my skills. Apart from blogging I have also little taste in artistic skills and literature, which can keep my writing and posts tangy.

Whether you stumbled in by chance or came here on purpose, I hope you find something that sparks your curiosity or makes you think a little deeper. Thanks for stopping by!!

Leave a comment