Skip to content
Programmingoneonone
Programmingoneonone
  • 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
Programmingoneonone

HackerEarth Little Shino and the tournament problem solution

YASH PAL, 31 July 2024
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

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