I cant understand and form the logic behind it can someone help me out?
Refer this for the approach : Playing with cards