You are not logged in. Please login at to post your questions!


A problem with Marbles-Practice(Medium) problem.

Hi! I am facing a problem here. I submit the following code but it is getting accepted.

But, the following does not get accepted. All these both codes do is the same, calculate n-1Ck-1

What is the thing I am missing?

Thank You!

asked 17 Sep '18, 01:57

shubhsy's gravatar image

accept rate: 0%

Because 2nd one is calculating ncr(n-1, k) instead of ncr(n-1, k-1)
Example for ncr(27,20) it should return 657800 i.e. N = 26 and K = 19
It is returning 230230 instead. i.e N = 26 and K = 20


answered 17 Sep '18, 13:07

babangain's gravatar image

accept rate: 4%


Thank you for pointing that out. That was due to me ignoring the case when the "if" statement is executed and the value of n is changed to n-r. I removed it and changed it to n-r+1. It works fine now. Thanks a lot. Cheers :)

(18 Sep '18, 03:23) shubhsy3★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 17 Sep '18, 01:57

question was seen: 128 times

last updated: 18 Sep '18, 03:23