← All problemsSign in

(SENIOR) The Math question

Piyush has array a, consisting of n integers a0,a1a2,an-1, and function f(x), taking an integer from 0 to 2n-1 as its single argument. Value f(x) is calculated by formula , where bit(i) equals one if the binary representation of number x contains a 1 on the ith position, and zero otherwise. For example, if n=4 and x=11 (11=20 + 21 + 23), then f(x)= a0 + a1 + a3. Help Piyush find the miximum of

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start