Maximize It Hackerrank Solution PythonMaximize It in python — HackerRank Solution

Sahilkushwah
2 min readJun 1, 2021

--

Maximize It in python — HackerRank Solution

Problem :

You are given a function f(x) = x². You are also given k lists. The ith list consists of Ni elements. You have to pick one element from each list so that the value from the equation below is maximized:

S = ( f(X1) + f(X2) + ……+ f(Xk))%M

Xi denotes the element picked from the ith list . Find the maximized value Smax obtained. % denotes the modulo operator.

Note that you need to take exactly one element from each list, not necessarily the largest element. You add the squares of the chosen elements and perform the modulo operation. The maximum value that you can obtain, will be the answer to the problem.

Input Format :

The first line contains 2 space separated integers k and m.
The next k lines each contains an integer Ni, denoting the number of elements in the ith list, followed by Ni space separated integers denoting the elements in the list.

Constraints :

  • 1 <= K <= 7
  • 1 <= M <= 1000
  • 1 <= Ni <= 7
  • 1 <= magnitude of element in list <= 10⁹

Output Format :

Output a single integer denoting the value Smax.

Sample Input :

3 1000
2 5 4
3 7 8 9
5 5 7 8 9 10

Sample Output:

206

Solution :

Click Here → Maximize It! Hackerrank Solution

--

--

Sahilkushwah
Sahilkushwah

Written by Sahilkushwah

0 Followers

Sahil Kushwah provides information about Python computer programming, hackerrank problem solution ,Tech News,Technology and Mobile Review in Hindi.

No responses yet