Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Little Shino and the tournament problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Little Shino and the tournament problem solution, Little Shino is interested in the fighting tournaments. Once she went to watch one of the tournaments. There were N fighters and ith fighter will be represented by i. Each fighter has some distinct strength. The rules of the tournament are:
 
Each fight will have 2 fighters.
In a fight, a fighter with more strength will win.
In one round, 1st fighter will fight against 2nd fighter, 3rd fighter will fight against 4th fighter and so on. If there is an odd number of fighters, the last one will qualify to the next round without fighting.
 
 
HackerEarth Little Shino and the tournament problem solution

 

 

HackerEarth Little Shino and the tournament problem solution.

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
bool B[30];

int main(int argc, char* argv[])
{
if(argc == 2 or argc == 3)
freopen(argv[1], "r", stdin);
if(argc == 3)
freopen(argv[2], "w", stdout);
string s;
int ans, count, k;
cin >> k >> s;
ans = 0;
for(int i = 0;i < s.length();++i)
{
count = 0;
memset(B, false, sizeof(B));
for(int j = i;j < s.length();++j)
{
if(B[s[j] - 'a'] == false) count++;
B[s[j] - 'a'] = true;
if(count == k)
ans++;
}
}
cout << ans << endl;
return 0;
}
 
 

Second solution

#include<bits/stdc++.h>

using namespace std;

int k;
string st;
int cnt[1000];
int ans;

int main(){

cin >> k;
cin >> st;

for (int l = 0; l < st.size(); l++)
{
for (int i = 'a'; i <= 'z'; i++)
{
cnt[i] = 0;
}

int dif = 0;

for (int r = l; r < st.size(); r++)
{
cnt[st[r]]++;
if (cnt[st[r]] == 1)
++dif;
if (dif == k)
++ans;
}
}

cout << ans << endl;

return 0;
}
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes