Let us understand the question first, we have to find the character in the given string which is repeated twice and first. Let us understand with examples:
- Suppose "Selenium Java" is the given string, in this string 'a' and 'e' repeated twice but 'e' character coming first, so the first duplicate character will be 'e'.
- Suppose "JEE2 JAVA" is the given string, in this string 'J', 'E" and 'A' repeated twice but 'J' character is coming first, so the first duplicate character is 'J'
Hope the question is clear now, let us implement the logic. We are going to use "HashMap" to solve this question.
Step 1: First we will convert the String to a Character Array
Step 2: Then add each character from the array to HashMap<K, V> as a key, value pair. While adding the character verify if the character is already present then increase the value by 1, otherwise just add it to HashMap<K, V> with value 1.
Step 3: Finally read each character from the character array and verify whose value is equal to 2, the first matched character will be first duplicate character in the given string.
Execute the above program for different inputs and verify the results.
Some sample outputs are below:
Please let me know if above logic is failing for any of your inputs, I will verify and update. Thanks!!
#HappyLearning #HappyCoding
Shines well. Thank you for the information.
ReplyDeleteJava Training in Bangalore
Best Java Training Institutes in Bangalore
Java Training in Madurai
Best Java Training Institute in Madurai
Java Training in Coimbatore
Java Course in Coimbatore
Great Article
Deleteandroid based projects
Java Training in Chennai
FInal Year Project Centers in Chennai
Java Training in Chennai
projects for cse
The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
Actually, recently see this blog! This is very great and very impressed. Thank you for giving the different post.
ReplyDeleteOracle DBA Training in Chennai
Oracle DBA Course in Chennai
Excel Training in Chennai
Oracle Training in Chennai
Spark Training in Chennai
Tableau Training in Chennai
Embedded System Course Chennai
Oracle DBA Training in Chennai
Oracle DBA Training in OMR
ReplyDeleteI would definitely thank the admin of this blog for sharing this information with us. Waiting for more updates from this blog admin.
Salesforce Course in Chennai
salesforce training institute in chennai
Angularjs Course in Chennai
Ethical Hacking Course in Chennai
Tally Course in Chennai
Salesforce Training in Chennai
Salesforce Training
great information.
ReplyDeletethank you for posting.
keep sharing.
Best java training in Bengaluru
ReplyDeleteThank you for posting this amazing information.
java training institute in south delhi
java training institute in Noida
Great Article. Thank you for sharing! Really an awesome post for every one.
ReplyDeleteIEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.
Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
ReplyDeleteThanks for your extraordinary blog. Your idea for this was so brilliant. This would provide people with an excellent tally resource from someone who has experienced such issues. You would be coming at the subject from a different angle and people would appreciate your honesty and frankness. Good luck for your next blog!
Tally ERP 9 Training
tally classes
Tally Training institute in Chennai
Tally course in Chennai
seo training classes
seo training course
seo training institute in chennai
seo training institutes
seo courses in chennai
seo institutes in chennai
seo classes in chennai
seo training center in chennai
I really appreciate your method to explaining, I hope to see more posts from your blog. thank you!
ReplyDeleteDigital Marketing Course In Kolkata
Web Design Course In Kolkata
SEO Course In Kolkata
I'm going to share with you the exact ten-step process I take companies through when developing their staff to think and act like business owners who make customers want to buy, buy again, and then go on to tell their friends and family to buy! Salesforce training in Hyderabad
ReplyDelete