HackerRank - Repeated String | Full Solution with Simplified Examples and Visuals | Study Algorithms

preview_player
Показать описание
In this problem you are given a string that is repeated infinite number of times, and you have to find the frequency of the character 'a' in the first 'n' letters. A good way to approach this problem is by using mathematical induction and predicting how the string would look like after several repetitions. Watch the video to understand the problem statement correctly, and how can we derive the mathematical formula to solve it efficiently. All along with visuals and animations.

Chapters:
00:00 - Intro
00:58 - Problem statement and description
02:56 - Brute Force Solution
04:26 - Efficient solution using maths
08:12 - Dry-run of the code
09:54 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

#hackerrank #programming #interview
Рекомендации по теме
Комментарии
Автор

great and clear explanation sir!!Thank you so much sir
Not only this sir, each and every video was awesome and easily understandable

shruthibudidha
Автор

bro you're just amazing👌👌.we want this type of teaching.

pradeeps
Автор

Really clear explanation.
Definitely helped to understand this interesting HackerRank problem and the optimal solution.
Many thanks!!

CostaKazistov
Автор

Thank you Sir, you taught it very well. <3

pratyakshamaheshwari
Автор

StringLeftLength=n%strLength;
Will be helpful?

vaitheeswaranr
Автор

Can you Please make it on Stock Span Problem

rohitsaka
Автор

why is the time complexity O(1)? You have run the two loops in the code

prativa
Автор

Why can't we use this
stringLeftLength=n%strLength;

_JAGATHEESANV
Автор

Sir....I tried the below code..
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
long long int n, count=0;
int length, i;
string sub_str;
getline(cin, sub_str);
cin>>n;
length = sub_str.length();
if(length==1)
{
if(sub_str[i]=='a')
{
count=n;
}
else
{
count=0;
}
}
// finding number of a's in substring
else if(length>1)
{
for(i=0;i<length;i++)
{
if(sub_str[i]=='a')
count++;
}
//finding total a's in n-substrings
int q = n/length;
count = q*count;
if(n%length!=0)
{
int rem = n%length;
//rem = no.of trailing letters which do not form a complete substring
for(i=0;i<rem;i++)
{
if(sub_str[i]=='a')
{
count++;
}
}

}
}
cout<<count;
return 0;
}

But only 14 test cases in hackerrank gave success msg.... rest of them failed...
Can i know the mistake??

niharikamurulidhara
Автор

Shouldn't you `Math.floor(n / sLength)` the number of reps?

ke
join shbcf.ru