Skip to content

Commit

Permalink
Gemstones
Browse files Browse the repository at this point in the history
  • Loading branch information
mboukhlouf committed Nov 7, 2022
1 parent 13fb583 commit 941f020
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions Algorithms/Strings/Gemstones/Solution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Result
{

/*
* Complete the 'gemstones' function below.
*
* The function is expected to return an INTEGER.
* The function accepts STRING_ARRAY arr as parameter.
*/

public static int gemstones(List<string> arr)
{
var gemsCount = arr
.SelectMany(rock => rock.Distinct())
.GroupBy(c => c)
.ToDictionary(group => group.Key, group => group.Count())
.Where(kvp => kvp.Value == arr.Count)
.Count();
return gemsCount;
}

}

class Solution
{
public static void Main(string[] args)
{
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);

int n = Convert.ToInt32(Console.ReadLine().Trim());

List<string> arr = new List<string>();

for (int i = 0; i < n; i++)
{
string arrItem = Console.ReadLine();
arr.Add(arrItem);
}

int result = Result.gemstones(arr);

textWriter.WriteLine(result);

textWriter.Flush();
textWriter.Close();
}
}
Binary file not shown.

0 comments on commit 941f020

Please sign in to comment.