We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
usingCategoryGroup=System.Collections.Generic.Dictionary<Category,int>;enumCategory{Positive,Negative,Zero}classResult{/* * Complete the 'plusMinus' function below. * * The function accepts INTEGER_ARRAY arr as parameter. */publicstaticvoidplusMinus(List<int>arr){vartotal=arr.Count();CategoryGroupcounts=newCategoryGroup{{Category.Positive,0},{Category.Negative,0},{Category.Zero,0},};arr.ForEach(n=>{if(n>0)counts[Category.Positive]++;elseif(n<0)counts[Category.Negative]++;elsecounts[Category.Zero]++;});printCounts(counts,total);}privatestaticvoidprintCounts(CategoryGroupcounts,inttotal)=>counts.Keys.ToList().ForEach(key=>Console.WriteLine(calcFraction(counts[key],total)));privatestaticstringcalcFraction(intcountOf,inttotal)=>((double)countOf/total).ToString("F6");}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →