Skip to content

Instantly share code, notes, and snippets.

@vedant1811
Created July 20, 2018 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vedant1811/9f08cffbf96726df0f12ad0c121e0656 to your computer and use it in GitHub Desktop.
Save vedant1811/9f08cffbf96726df0f12ad0c121e0656 to your computer and use it in GitHub Desktop.
def catch(arr, k)
ps = 0
ts = 0
count = 0
arr.each do |e|
if e == 'T'
if ps > 0
ps -= 1
count += 1
else
ts += 1 unless ts >= k
end
else
if ts > 0
ts -= 1
count += 1
else
ps += 1 unless ps >= k
end
end
end
count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment