If you find this tutorial helpful, please do not forget to like , comment, share and It would be great if you can leave your feedback about the tutorial, as I have put a lot of hard work to make things easy for you. Thanks ..!! 🙏🙏🙏
@eyobghebremicael57913 жыл бұрын
As the repeated string isn't important, we can calculate the count of a's easily as follows public static int counta(String a, int n){ int len = a.length(); int count=0; //empty string if (len==0){ return 0; } for (int j=0;j
@jenish98543 жыл бұрын
Osm bro...
@randiaz953 жыл бұрын
This implementation is slow for anything above a million
@B3Band2 жыл бұрын
@@randiaz95 Check mine. Way faster since you don't actually check n letters of the string. Plus this one is lossy. If n > 2^31 the for loop can't handle it because you used an int. It shouldn't even compile.
@raba6504 жыл бұрын
I use JavaScript as my choice for these challenges, but your explanation still allowed me to better understand the problem as we as come up with & understand a solution. Thank for the clearness.
@JavaAidTutorials4 жыл бұрын
You're very welcome!
@navinchainani47214 жыл бұрын
Hi send this code in javascript email is chainani.navin97@gmail.com
@pritamhalder57236 ай бұрын
bhai please help me my email and Facebook hacking they are force fully asking money for me very urgent my account please suggest me please 🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@davidtemidayo854110 ай бұрын
Hello, thank you for this tutorial, i was able to write this using javaScript and it works function evaluateValue(s,n){ const sLength = s.length; const quotient = Math.floor(n / sLength); const r = n % sLength; const freqA = s.match(/a/g).length; const useRemainder= (r > 0) ? s.slice(0, r).match(/a/).length : 0 const a = quotient * freqA + useRemainder; return a; } evaluateValue("abc", 1000000000000);
@TheManishYadav013 жыл бұрын
This is best plateform of learning code, 👍👍
@gamer-zy1uj3 жыл бұрын
Perfect👍 thanks 😊 you taught so calmly and your teaching way is literally nice .keep going on and please upload more videos on the questions which are asked by fang frequently in java itself🙏🙏🙏🙏🙏🙏 please sir🤗
@NitishKumar-un9ev2 жыл бұрын
The most toughest thing in HackerEarth is understanding the problem/Question
@pritamhalder57236 ай бұрын
Help me please
@anil20094 жыл бұрын
Guruji you are great!!
@JavaAidTutorials4 жыл бұрын
😀
@lasithadulshan73574 жыл бұрын
Exellent teaching!! Grow up 💪🏽
@jlecampana4 жыл бұрын
Fantastic way of solving it! Thank you.
@JavaAidTutorials4 жыл бұрын
Happy to help!
@jn28698 ай бұрын
Great teaching, you are awesome, keep up the good work
@rocker315903 жыл бұрын
Wow awesome 👏🏼
@darrellwalker21493 жыл бұрын
public static int AddString(string _str, int n) { string newStr = string.Empty; while(newStr.Length < n) { newStr += _str; } return newStr.Substring(0,n).ToCharArray().Where(x=>x.ToString() =="a").Count(); }
Excellent, but what if the a character is present in the middle of the string i.e. s = "bac"?
@mayanksrivastava44524 жыл бұрын
Great as Usual....
@programminginc85393 жыл бұрын
excellent approach
@archana094242 жыл бұрын
Wonderful explanation sir.Thank you for educating us.
@harshmanola5634 жыл бұрын
long size = s.length(), repeated = n/size; long left = n - (size * repeated); int extra = 0; int count = 0; for(int i = 0; i < size; i++){ if(s.charAt(i) == 'a'){ ++count; } } for(int i = 0; i < left; i++){ if(s.charAt(i) == 'a'){ ++extra; } } repeated = (repeated * count) + extra; return repeated;
@B3Band2 жыл бұрын
Lossy. Your for loop uses int, but it's expected to loop a long number of times.
@hoddybhaba6704 Жыл бұрын
Nice explaination!
@JavaAidTutorials Жыл бұрын
Glad it was helpful!
@faizandarwesh78672 жыл бұрын
Quality content.
@youshinde3674 жыл бұрын
Great As usual thank you so much
@nareshle31592 жыл бұрын
Hii sir am Naresh Can you please tell elobourately about coding in eclipse ide so that coding beginners also easily understand
@daromarra58233 жыл бұрын
Perfect! Thanks!
@Shohan015 ай бұрын
What if the s = ‘bac’ how does that match formula works?
@mohankadam49834 жыл бұрын
Thank you so much Sir....It's very helpful
@JavaAidTutorials4 жыл бұрын
Most welcome
@michaeljackson60434 жыл бұрын
I will calculate the number of a's of given string and then using n integer , i calculate the n/len(s) and n%len(s) result=(n/len(s)*no.of.a's) +how many chracters in n%len(s) substring
@B3Band2 жыл бұрын
Similar to my posted solution (i posted the actual java). Substring can only take int (and n is long), but Since String can only hold 2^31, you know casting (n % length) to int will work.
@B3Band2 жыл бұрын
public static long repeatedString(String s, long n) { int length = s.length(); //length of s long repeats = n / length; //if n is 10 and length is 3, repeats 3 times long append = n % length; //the extra substring at the end of the infinite string String suffix = s.substring(0, (int)append); //10 % 3 = 1, so append one letter to String //we know String can only hold 2^31, so //casting to an int is okay! long count = s.chars().filter(ch -> ch == 'a').count(); //this is how you count chars in Java 8+ //count the a chars in the original string long extraBit = suffix.chars().filter(ch -> ch == 'a').count(); //now count the extra chars from the substring long total = count * repeats + extraBit; //the total number of a chars. Return it! return total; }
@justfun4976 Жыл бұрын
What is the use of sc.close()
@simsonpeak31192 жыл бұрын
Sir, does string should always start with a, what if the s=bca ,n=10 and 10%3 =1 and 10/3=3 and a occurrence will be 4 as per your code. But actual a occurrence is 3.
@nareshkoude21332 жыл бұрын
Correct !! it won't work...
@sulemani2482 Жыл бұрын
first of all thanks sir, but I would like to know can we prepare ourself for .net core on macbook, I am facing an issue of connection string with database on mac after learning c# and sql
@memesmacha614 жыл бұрын
Loved it..!
@manvirchoudhary1073 жыл бұрын
Thank you sir for the teaching. Would you tell us how we can come up with this kind of mathematical approach ? where we can learn ?. I am able to do simple brute force approach .Request from you please dont stop making videos on problem solving. Please do more videos on that,
@mahmmadhusen67944 жыл бұрын
Nice explanation
@JavaAidTutorials4 жыл бұрын
Thank you ☺️
@SarfrazRazaOfficial3 жыл бұрын
which software you are using for writing on the board...???
@hareeshhari92934 жыл бұрын
Hi thank you so much for the solution its really helpful I was little confused in partiallength calculation could you please explain
@JavaAidTutorials4 жыл бұрын
You still have this doubt for partial length logic or its cleared now ?
@pasumarthiashik10993 жыл бұрын
@@JavaAidTutorials can u explain for loop
@srinivaskaribandi10893 жыл бұрын
@@pasumarthiashik1099 in python my way of sloving s=input() n=int(input()) list_a=[] lenth_of_stng=len(s) nums_add1=n//lenth_of_stng nums_add2=n%lenth_of_stng req1=nums_add1*s req2=s[:nums_add2] total=req1+""+req2 first_letter=total[0] count=0 for j in total: if first_letter==j: count+=1 print(count)
@coffeemaker6933 жыл бұрын
you no need to concatenate the string, better split string into Individual character first. in C# as easy as : stringObj.ToArray(); in java as simple as : String s1="hello"; char[] ch=s1.toCharArray();
@pasumarthiashik10993 жыл бұрын
why have u taken acount and can u explain the for loop because string length in for loop is 3 or 10???
@srinivaskaribandi10893 жыл бұрын
My way of sloving problem like this s=input() n=int(input()) list_a=[] lenth_of_stng=len(s) nums_add1=n//lenth_of_stng nums_add2=n%lenth_of_stng req1=nums_add1*s req2=s[:nums_add2] total=req1+""+req2 first_letter=total[0] count=0 for j in total: if first_letter==j: count+=1 print(count)
@MynameisJanRed3 жыл бұрын
Thank you
@JavaAidTutorials3 жыл бұрын
You're welcome
@shraddhapawar56743 жыл бұрын
Can we edit main function given by hackerrank .
@mohamedfarhan58942 жыл бұрын
I have tried python3, and my code works well. But it won't work for very large n values (more than 8-digit) .please check and give suggestions . def char_occ(s,n,char): k = s*n return k[0:n].count(char) examples >char_occ('abcac',10,'a') >4 >char_occ('aba',10,'a') >7
@orchidnewbie3 жыл бұрын
Thank you for the video. What is the Time Complexity on this solution, max s.Length
@yashwanthchigari142 жыл бұрын
It's going to be linear: O(n)
@coffeemaker6933 жыл бұрын
C# version , my solution static void Main(string[] args) { string s = "aba"; Console.WriteLine(RepeatString(10, s)); Console.ReadKey(); } private static int RepeatString(int n, string s) { string result = string.Empty; var characters = s.ToArray(); var countA = 0; for (int i = 0, index = 0; i < n; i++, index++) { if (index == characters.Length) index = 0; if (characters[index] == 'a') countA++; result += string.Concat(characters[index]); } Console.WriteLine(result); return countA; }
@prasuguna3 жыл бұрын
If it's bca then this formula fails?
@babr54013 жыл бұрын
why you usen't stream ?
@anandkatam81502 жыл бұрын
Sir please make hacker rank python preparation kit solutions also please sir
@arjishat3 жыл бұрын
java7 , java8, java15 er modde partokko ta ki??
@NateFreestyle8 ай бұрын
HackerRank classifies this as easy? I'm not sure I agree with that.
@hariprasad17273 жыл бұрын
How We Need To Set Environment In Web IDE For Spring Boot Applications
@genericbinary558 Жыл бұрын
what about "baac" and n=13 🙂
@kuldeepsinghrajput26003 жыл бұрын
why u used long for storing values?
@NateFreestyle8 ай бұрын
To take into account very large input values.
@ashutosh33874 жыл бұрын
Is there any complete course of dsa in java
@JavaAidTutorials4 жыл бұрын
Currently we do not have any courses yet, but lot of subscribers asked this question, so planning to create in future and inform you all. :)
@samiksharamteke28552 жыл бұрын
long repeatedString(string s, long n) { long freq = n /s.length(); long remains = n % s.length(); int count = 0; for(int i=0;i
@shenth274 жыл бұрын
Quite a bit complicated solution. I'd simply loop n number of times, maintains another index for the s, which I resets every time index >=s.length(). Then in the loop just increment the counter whenever you find 'a'. But I guess not an optimal solution if n is huge number though.
@JavaAidTutorials4 жыл бұрын
yes , if n is huge, it will not pass all TCs
@B3Band2 жыл бұрын
"simply" loop n times, when n can be 10^12 hahahaha Very slow solution. Check out mine, which only checks the original String, not the infinite string.
@IdontWatchIsee4 жыл бұрын
I didnt understand how you translate the algorithm in code :((( what can i do to understand this part better?? Please help
@JavaAidTutorials4 жыл бұрын
Do write lots of code. Learn more about your chosen programming language what are the utils , functionality etc it offers and do practice. you will see the difference. practice is the only key which can quickly help you to translate algorithm into code.
@IdontWatchIsee4 жыл бұрын
@@JavaAidTutorials thank you very much for taking the time to answer ❤️
@abhisekpanda37012 жыл бұрын
import java.util.Scanner; public class recur { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter the word"); String word=sc.next(); System.out.println("Enter the number"); int num=sc.nextInt(); long l=(num/(word.length())); long l1=num%(word.length()); String s=sort(word,l,l1); System.out.println(s); } static String sort(String word,long l , long l1) { String str=""; char ch1=' '; for(int i=0;i
@hariprasad17273 жыл бұрын
WEB IDE I am Not able To Understand
@salilkumarghosh98614 жыл бұрын
Sir can I solve these problems using C after watching all videos?
@JavaAidTutorials4 жыл бұрын
We always try to teach generic algorithm which is independent of any specific language. so you can use any language to implement the same .
@tauqeerahmed1366 Жыл бұрын
If someone wants to see this in swift let c = "baa" let n = 10 func checkNoOfCharactersIn(souceString : String , character : Character) -> Int { var count = 0 for char in souceString { if character == char { count += 1 } } return count } func getSubstringToString(sourceString : String,to : Int) -> String { return String(sourceString[.. Int { var answer = 0 let lengthOfOneTimeString = sourceString.count let repeatTimese = n / lengthOfOneTimeString let reminderLimit = n % lengthOfOneTimeString answer = checkNoOfCharactersIn(souceString: sourceString, character: "a") answer = answer * repeatTimese answer = answer + checkNoOfCharactersIn(souceString: getSubstringToString(sourceString: sourceString, to: reminderLimit), character: "a") return answer } var count = numberOfTimeAInNLetters(sourceString: c, n: n)
@PrivacyRocksАй бұрын
Your heavy India/pakistani accent makes it impossible to understand you. I’m looking for someone else