John has discovered various rocks. Each rock is composed of various  elements, and each element is represented by a lowercase Latin letter  from 'a' to 'z'. An element can be present multiple times in a rock.  An element is called a 'gem-element' if it occurs at least once in  each of the rocks.Given the list of rocks with their compositions, you have to print how  many different kinds of gems-elements he has.Input FormatThe first line consists of N, the number of rocks. Each of the next N  lines contain rocks composition. Each composition consists of small  alphabets of English language.Output FormatPrint the number of different kinds of gem-elements he has.Constraints\$1  N  100\$Each composition consists of only small Latin letters ('a'-'z'). 1  Length of each composition  100Sample Input3abcddebaccdeeabg Sample Output2 ExplanationOnly a, b are the two kind of gem-elements, since  these characters occur in each of the rocks composition.I tried to solve this HackerRank problem in C#, however my code is not passed ALL tests. I've tested many times my code and it seems to me it should work. Please, guys, do you see any mistakes?static void Main(string[] args){    Console.WriteLine(Input quantity of rocks:);    int quantityRocks;    int.TryParse(Console.ReadLine().ToLower(), out quantityRocks);    //  Getting inputted rocks    if (quantityRocks > 0 && quantityRocks <= 100)    {        List<string> rocks = new List<string>();        HashSet<char> uniqueLetters = new HashSet<char>();        foreach (var word in rocks){           foreach (var c in word)                uniqueLetters.Add(c);        }        //  Putting rocks in a list of rocks        for (int count = 0; count < quantityRocks; count++){           Console.WriteLine(Input a rock:);           string currentRock = Console.ReadLine();           rocks.Add(currentRock);           //  Getting unique letters           foreach (var c in currentRock) {               uniqueLetters.Add(c);           }        }        //Logic to find out repeated rocks                        int quantityOfRepeating = FindGemElements(uniqueLetters, rocks);                        if (quantityOfRepeating != 0) {            Console.WriteLine(quantityOfRepeating);        }        else {            Console.WriteLine(There is no  repeated letters in all words);        }    }}and function which finds gem stones:public static int FindGemElements(HashSet<char> uniqueLetters, List<string> rocks){    int quantityRocks = rocks.Count;    int quantityOfRepeating = 0;    foreach (var letter in uniqueLetters)    {        quantityRocks = rocks.Count;        foreach (var word in rocks)        {           if (word.IndexOf(letter) != -1)           {              //no actions as we find gem element           }           else           {              quantityRocks--;//decrement cause there is no gem element           }        }        //if quantityRocks leaves the same,         //it means we've found gem element and increment it            if (quantityRocks == rocks.Count)            {                quantityOfRepeating++;            }        }        return quantityOfRepeating;}Any advice, remarks are welcome and will be highly appreciated.Update:The reason was that that I should remove everywhere Console.WriteLine(), except where result should be outputted(Console.WriteLine(quantityOfRepeating);).
Finding repeated letters in a list of words
c#;algorithm;programming challenge
This is the most useful hint in the problem:Each composition consists of only small Latin letters ('a'-'z')Since you are doing a challenge, if I did it for you, you will not learn much from it. But here is a BIG hint I will give you:There are 26 characters (a-z). So make all of them gems. Now I will give you the first word: bobGuess what? That first word I gave you, made all the letters, except for b and o, NOT gem. No more hints.Now about your code:You have this condition and if it is true, then all your code is inside it:if (quantityRocks > 0 && quantityRocks <= 100){    // code }I would do this instead so the whole code block is not indented and it also shows there is nothing to do:bool withinRange = quantityRocks > 0 && quantityRocks <= 100;if (!withinRange){    return; // or do whatever you want}// It is within range so the rest of your code can go hereIn the following code you create a list and a hashset and then you traverse it: but what you are traversing through if you just created it?List<string> rocks = new List<string>();HashSet<char> uniqueLetters = new HashSet<char>();foreach (var word in rocks){    foreach (var c in word)        uniqueLetters.Add(c);}In the following code you are traversing the words to search and see if they all have a letter. As soon as one does not have a letter, you know your answer that the letter is not a gem so why waste time and keep searching? Also you are not doing nothing in your if block so why do you have it?foreach (var word in rocks){    if (word.IndexOf(letter) != -1)    {        //no actions as we find gem element    }    else    {        quantityRocks--;//decrement cause there is no gem element    }}Furthermore, try and write optimistic conditions if possible, your code will be easier to read. Like this:foreach (var word in rocks){    if (word.IndexOf(letter) == -1)    {        quantityRocks--;//decrement cause there is no gem element    }    // no else needed}MOST IMPORTANT POINTWhat you are doing is a sequential search. I am sure this challenge is looking for an optimal search method. Therefore, you should try and use a better searching technique. See here for the different searching techniques.Try creating a flowchart using good old fashioned approach with a pencil and paper. Think about your approach, see when you can stop searching, see what other ways you can optimize the search. Once you have a clear picture of what you want to do, put the flowchart in front of you and then convert the flow chart into code. If your code does not provide the correct result, do a walkthrough of your code to see where the issue could be. Then fix your flowchart, and change your code. Repeat until everything works.When you are writing the code, try and concentrate on the algorithm of finding the gem letter given a set of words. Therefore, instead of using the console to enter the words, hardcode them into your code so you do not have to keep entering them. Your algorithm should not care about where the words are coming from. var words = new List<string> { One, Two, Other /*, ... and so on */};Create a list like above but make it a good set of words so you can test different scenarios. Then just keep testing that list.Remember that writing code is the easiest part. The hard part is having a good solution (approach).