hackerrank/interview_preparation_kit_dictionaries_and_hashmaps.rb
# Complete the sherlockAndAnagrams function below.

Complete the sherlockAndAnagrams function below.
Complete the sherlockAndAnagrams function below .
def sherlockAndAnagrams(s)
  chk = lambda { |a,b| a.sort == b.sort }
  result = []
  1.upto(s.size-1) do |i|
    cmb = s.chars.each_cons(i).combination(2).to_a
    result += cmb.select do |c|
      chk.call(c[0], c[1])
    end
  end
  result.size
end
def sherlockAndAnagrams ( s ) chk = lambda { | a , b | a . sort == b . sort } result = [ ] 1 . upto ( s . size - 1 ) do | i | cmb = s . chars . each_cons ( i ) . combination ( 2 ) . to_a result += cmb . select do | c | chk . call ( c [ 0 ] , c [ 1 ] ) end end result . size end
Complete the sherlockAndAnagrams function below.
Complete the sherlockAndAnagrams function below .
s
<not_specific>