GeeksforGeeks » Interview Questions

Microsoft - Find the number of ways of placing 3 balls in 3 buckets

(3 posts)
  • Started 7 months ago by abc
  • Latest reply from Prateek Caire
  1. abc
    guest
    Posted 7 months ago #

    Find the number of ways of placing 3 balls in 3 buckets. buckets are of diff capacity.
    bucket1 can hold 2 balls
    bucket2 - 3 balls
    bucket3 - 2 balls.

    ex. 1 1 1 is valid
    0 3 0 is valid

  2. Nascent
    guest
    Posted 7 months ago #

    111
    120
    102
    012
    021
    030
    201
    210

  3. Prateek Caire
    guest
    Posted 5 months ago #

    c = 0
    N(n)
    	for each i from 0 to 2
    		for each j from 0 to 3
    			for each k from 0 to 2
    				if(i + j + k == n)
    					c++
    	return c
    
    main()
    	N(3)
    

Reply

You must log in to post.

RSS feed for this topic