Gemstones in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct]

Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.

In this post, you will find the solution for Gemstones in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

Introduction To Algorithm

The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results. 

Advantages of Algorithms:

  • It is easy to understand.
  • Algorithm is a step-wise representation of a solution to a given problem.
  • In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.

Link for the ProblemGemstones – Hacker Rank Solution

Gemstones – Hacker Rank Solution


There is a collection of rocks where each rock has various minerals embeded in it. Each type of mineral is designated by a lowercase letter in the range . There may be multiple occurrences of a mineral in a rock. A mineral is called a gemstone if it occurs at least once in each of the rocks in the collection.

Given a list of minerals embedded in each of the rocks, display the number of types of gemstones in the collection.


The minerals  and  appear in each rock, so there are  gemstones.

Function Description

Complete the gemstones function in the editor below.

gemstones has the following parameter(s):

  • string arr[n]: an array of strings


  • int: the number of gemstones found

Input Format

The first line consists of an integer , the size of .
Each of the next  lines contains a string  where each letter represents an occurence of a mineral in the current rock.


 | arr[i] | 
Each composition  consists of only lower-case Latin letters (‘a’-‘z’).

Sample Input

STDIN       Function
-----       --------
3           arr[] size n = 3
abcdde      arr = ['abcdde', 'baccd', 'eeabg']

Sample Output



Only  and  occur in every rock.

Gemstones – Hacker Rank Solution
import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        int N;
        Scanner in = new Scanner(;
        N = in.nextInt();
        String s;
        int[] count = new int[26];
        int[] temp;
        for (int i = 0; i < N; i++) {
            temp = new int[26];
            s =;
            for (char c : s.toCharArray()) {
                temp[c - 97] += 1;
                if (temp[c - 97] == 1)
                    count[c - 97] += 1;
            temp = null;
        int sum = 0;
        for (int i = 0; i < 26; i++) {
            if (count[i] == N)
                sum += 1;
        count = null;//garabage collector

126 thoughts on “Gemstones in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct]”

  1. While generally, it is ok to use a VPN to access non-cash games, some services like PokerStars and 888poker could ban your account and not let you withdraw funds if used in a real money game, so take care to make sure you only use them for free games. Always check with the terms and conditions of a poker web app before using a VPN to make sure it is ok to use them. One more thing. There are some poker apps that will attempt to force you to complete in-app purchases in order to keep your games going. Avoid them like the plague! No legitimate poker site would ever do such a thing. Who says you only have to play poker at your poker night? Elevate your ordinary poker night into a full-blown casino night with games like roulette, craps, or even some homemade slot machines. You’ll have tons of options for guests that aren’t into poker but still want to have a good time with their friends.
    We’ve got all kinds of Poker games, from Texas Hold ‘Em titles like Five-Card Draw (in Video Poker). Play Vegas-style in Vegas Poker, or grab your guns and head for a more serious game in the Old West in the Governor of Poker series. Pick your setting and place your bets! We may as well start as we mean to go on, by using offline play to increase your skills. That’s where Learn Poker comes in. Developed by the folks behind Governor of Poker, this app is designed to get you up to speed with the game. It is free to play and will walk you through the basics, hand combinations, tactics, bluffing and then get you to play a real game. I only played for 20 minutes or so but the app seemed very easy to follow. The tooltips are useful and descriptive and the pace is just right, at least it was for me. If you want to learn to play Texas Holdem, this is a good way to do it.

  2. Buying Bitcoin and other cryptocurrencies at Germany is now easier than ever with Bit2Me. Buying Bitcoin with a debit card has become relatively easy in the past few years with the introduction of anti-fraud systems for Bitcoin exchanges. However, these systems are quite expensive to operate and therefore exchanges will usually charge a premium for buying Bitcoin with a debit card. Sorry to hear you are having a hard time to register at a bitcoin site. The information above where it says “QUICK GUIDE: HOW TO BUY BITCOIN IN THE US” carefully explains how you can trade Bitcoins in the US. Google Pay is a convenient way to deposit funds on the world’s top crypto exchanges. With Uphold, you can instantly buy & stake over 250 coins with zero fees and no waiting time from anywhere in the world. By following these steps, you’ll be able to quickly and securely buy crypto with a GPay deposit.
    Just how many bitcoins are there? Well in easy, simple words, ever since bitcoin went live in January 2009, the total supply has been capped at 21 million. At the time of writing, over 18.999 million of them have been mined, according to CoinMarketCap. While politicians in the U.S. tend to earn substantial salaries, it’s usually not indicative of their true wealth. More: Celebrities Who Are Even Richer Than You ThinkAdvice: 3 Things You Must Do When… Cryptocurrencies were once believed to be a distant dream when developers first came up with the concept and began exploring potential solutions to bring the dream to life back in the 1990s. However, over a decade after the concept was born, a developer with the alias Satoshi Nakamoto introduced bitcoin. This coin featured revolutionary design concepts that enabled it to work in ways that developers once only dreamed of. Since the emergence of bitcoin, there have been several other cryptocurrencies that have come to the scene to take their own piece of the cryptocurrency pie.

  3. To presume from actual news, ape these tips:

    Look for credible sources: It’s material to secure that the newscast source you are reading is respected and unbiased. Some examples of good sources tabulate BBC, Reuters, and The Fashionable York Times. Review multiple sources to get a well-rounded aspect of a isolated statement event. This can better you get a more complete facsimile and keep bias. Be in the know of the angle the article is coming from, as flush with reputable news sources can contain bias. Fact-check the low-down with another commencement if a expos‚ article seems too sensational or unbelievable. Till the end of time be persuaded you are reading a known article, as news can change-over quickly.

    By following these tips, you can fit a more au fait scandal reader and more wisely understand the everybody around you.

  4. Altogether! Find info portals in the UK can be crushing, but there are tons resources accessible to cure you mark the perfect the same for you. As I mentioned formerly, conducting an online search with a view “UK newsflash websites” or “British intelligence portals” is a vast starting point. Not one desire this give you a comprehensive shopping list of report websites, but it will also provender you with a punter understanding of the common communication view in the UK.
    In the good old days you be enduring a file of imminent story portals, it’s prominent to value each undivided to choose which upper-class suits your preferences. As an exempli gratia, BBC Dispatch is known in place of its ambition reporting of information stories, while The Custodian is known quest of its in-depth analysis of partisan and sexual issues. The Unconnected is known for its investigative journalism, while The Times is known by reason of its business and funds coverage. Not later than entente these differences, you can decide the rumour portal that caters to your interests and provides you with the news you have a yen for to read.
    Additionally, it’s quality looking at close by scuttlebutt portals because explicit regions within the UK. These portals lay down coverage of events and dirt stories that are relevant to the область, which can be specially utilitarian if you’re looking to hang on to up with events in your neighbourhood pub community. In search instance, provincial dope portals in London classify the Evening Standard and the Londonist, while Manchester Evening News and Liverpool Echo are popular in the North West.
    Overall, there are numberless bulletin portals available in the UK, and it’s significant to do your inspection to remark the united that suits your needs. Sooner than evaluating the unconventional news broadcast portals based on their coverage, dash, and essay viewpoint, you can decide the one that provides you with the most fitting and interesting info stories. Meet success rate with your search, and I ambition this information helps you find the just right news broadcast portal inasmuch as you!

  5. Your writing style effortlessly draws me in, and I find it nearly impossible to stop reading until I’ve reached the end of your articles. Your ability to make complex subjects engaging is indeed a rare gift. Thank you for sharing your expertise!

  6. This article is a true game-changer! Your practical tips and well-thought-out suggestions hold incredible value. I’m eagerly anticipating implementing them. Thank you not only for sharing your expertise but also for making it accessible and easy to apply.

  7. Your storytelling prowess is nothing short of extraordinary. Reading this article felt like embarking on an adventure of its own. The vivid descriptions and engaging narrative transported me, and I eagerly await to see where your next story takes us. Thank you for sharing your experiences in such a captivating manner.

  8. In a world where trustworthy information is more crucial than ever, your dedication to research and the provision of reliable content is truly commendable. Your commitment to accuracy and transparency shines through in every post. Thank you for being a beacon of reliability in the online realm.

  9. Your blog is a true gem in the vast expanse of the online world. Your consistent delivery of high-quality content is truly commendable. Thank you for consistently going above and beyond in providing valuable insights. Keep up the fantastic work!

  10. I wanted to take a moment to express my gratitude for the wealth of invaluable information you consistently provide in your articles. Your blog has become my go-to resource, and I consistently emerge with new knowledge and fresh perspectives. I’m eagerly looking forward to continuing my learning journey through your future posts.

  11. In a world where trustworthy information is more crucial than ever, your dedication to research and the provision of reliable content is truly commendable. Your commitment to accuracy and transparency shines through in every post. Thank you for being a beacon of reliability in the online realm.


Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker🙏.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock