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 The Normal Type problem solution

YASH PAL, 31 July 2024
In this HackerEarth The Normal Type problem solution There are a lot of Poke’mons who are jealous of the fact that they do NOT have any specialty, they’re the… normal type of Poke’mon. But, what they fail to realize is that their power is their normalcy, the ability to think, rationalize and then act.
But, they do have an additional power… Poke’mons like Jigglypuff – which are normal, can figure out if a trainer is real or is a part of Team Rocket. And they need to use their power to a great extent.
In an array, which consists of N elements, A1, A2, …, AN, if a subarray has the total number of distinct elements as that of the original array, that determines the presence of Team Rocket.
You’ve to help the normal type Poke’mons in figuring out the total number of subarrays having total number of distinct elements same as that of the original array.
HackerEarth The Normal Type problem solution

HackerEarth The Normal Type problem solution.

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define f first
#define s second
#define pi pair<ll, ll>
#define pii pair<pi,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define maxn 3000001
int A[200011];
int main(){
freopen("in10.txt","r",stdin);
freopen("out10.txt","w",stdout);
int N;
cin >> N;
set<int>parent;
rep(i,N){
cin >> A[i];
parent.insert(A[i]);
}

ll ans=0;
set<int>s;
int j=0;
map<int,int>M;
rep(i,N){
j=max(j,i);
while(j<N and s.size()<parent.size()){
M[A[j]]++;
if(M[A[j]]==1){
s.insert(A[j]);
}
j++;
}
if(s.size()==parent.size())
ans+=N-j+1;
M[A[i]]--;
if(M[A[i]]==0) s.erase(A[i]);
}
cout<<ans;
}
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