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.
functiongemstones(arr:string[]):number{// sort stones by lengthletstones=arr.sort((a,b)=>a.length-b.length)// take the smallest stone, get collection of gems inside itletgems=Array.from(newSet<string>(stones.shift().split('')))// the rest of stones should have gems to be count as gemstone.returngems.filter(gem=>stones.every(stone=>stone.includes(gem))).length}
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 →
My answer with Typescript