Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.23 KB | None | 0 0
  1. def solve s, k
  2.   h = Hash.new(0)
  3.   s.chars.sort[0...k].each { |e| h[e.to_sym] += 1 }
  4.   s = s.chars
  5.   o = []
  6.   s.each do |v|
  7.     if h[v.to_sym] > 0
  8.       h[v.to_sym] -= 1
  9.     else
  10.       o << v
  11.     end
  12.   end
  13.   o.join
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement