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.
publicstaticintgemstones(List<String>arr){List<String>uniqueChar=newArrayList<>();intgemstones=0;// For each string, add all characters in uniqueCharfor(inti=0;i<arr.size();i++){uniqueChar.addAll(Arrays.asList(arr.get(i).split("")));}// Removing duplicate charactersuniqueChar=newArrayList<>(newLinkedHashSet<>(uniqueChar));for(inti=0;i<uniqueChar.size();i++){Stringc=uniqueChar.get(i);intcounter=0;for(intj=0;j<arr.size();j++){Stringstr=arr.get(j);counter+=(str.indexOf(c)!=-1)?1:0;}gemstones+=(counter==arr.size())?1:0;}returngemstones;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Gemstones
You are viewing a single comment's thread. Return to all comments →
Java