Problem Statement:
Refer: Maximize It! | HackerRank
Solution:
maximize.py
Python
import itertoolsdef 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))
Output:
All tests passed!
Please feel free to drop any suggestions or input.
Happy coding!!!
