Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerEarth Charged Up Array problem solution

YASH PAL, 31 July 2024
In this HackerEarth Charged Up Array problem solution, You are given an array A of size N. An element Ai is said to be charged if its value(Ai) is greater than or equal to Ki. Ki is the total number of subsets of array A, that consist of element Ai. 
The total charge value of the array is defined as the summation of all charged elements present in the array mod (10 to power 9 plus 7). Your task is to output the total charge value of the given array A.
HackerEarth Charged Up Array problem solution

HackerEarth Charged Up Array problem solution.

#include <bits/stdc++.h>
#define M 1000000007
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin>>T;
while(T--)
{
int N;
cin>>N;
long long arr[N];
for(int i=0;i<N;i++)
cin>>arr[i];
if(N>=64)
cout<<0<<endl;
else
{
long long val=(1ll<<(N-1));
long long ans=0;
for(int i=0;i<N;i++)
if(arr[i]>=val)
ans=(ans+arr[i]%M)%M;
cout<<ans<<endl;
}
}
}
coding problems

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes