Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • 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
Programmingoneonone

HackerEarth Uniqueness violation problem solution

YASH PAL, 31 July 2024
In this HackerEarth Uniqueness violation problem solution you are given an integer N. You are provided with an array of exactly N integers denoted by Ai. Also, you are provided with the uniqueness value for each array element and is denoted as Ui. Your task is to pick the array elements in such a way that no two adjacent array elements picked have the same value of uniqueness and the sum of values picked is maximum.
HackerEarth Uniqueness violation problem solution

HackerEarth Uniqueness violation problem solution.

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

int main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin>>T;
while(T--)
{
int N,M;
cin>>N;
int color[N];
for(int i=0;i<N;i++)
cin>>color[i];
int arr[N];
for(int i=0;i<N;i++)
cin>>arr[i];
int ans=0;
for(int i=0;i<N;)
{
int j=i;
int maxval=arr[i];
for(j=i;j<N;j++)
if(color[i]==color[j])
maxval=max(maxval,arr[j]);
else
break;
i=j;
ans+=maxval;
}
cout<<ans<<endl;
}
}
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes