Click here to Skip to main content
15,886,734 members
Please Sign up or sign in to vote.
1.00/5 (5 votes)
See more:
Problem Description
Alice has got a Random Number Generator. The generator generates a random number from 1 to N equiprobably.
Now Alice wants to know the expected number of turns until K distinct elements are generated.
Help Alice find this value modulo 109+7.

Problem Constraints
1 ≤ K ≤ N ≤ 105

Input Format
Input consists of 2 arguments, N=A and K=B in this order.

Output Format
Return a single integer, the expected value modulo 109+7

Example Input
  Input 1:
    N = 2
    K = 1

  Input 2:
    N = 2
    K = 2

Example Output
  Output 1:
    1

  Output 2:
    3

Example Explanation
  Explanation 1:
Whatever number is generated in the first turn will be unique and thus the answer is 1

  Explanation 2:
There are 2 cases:
First number generated is 1. The expected turns for getting a 2 later is 2.
First number generated is 2. The expected turns for getting a 1 later is 2.
So, final expected value is 1 + (2+2)/2 = 3.


What I have tried:

I tried to understand the question from 15th sep 2020 till now but, I am unable to understand the question.
I was stuck because the sample inputs looks easy but consider inputs as N=3 and K=2 the output for this is 500000006
Please explain if any one understood the question. I am not expecting the complete answer but a way to solve the problem.
Thank you.
Posted
Updated 30-Mar-21 0:14am
v3
Comments
BillWoodruff 19-Sep-20 8:09am    
modulo 100000000 + 7 is just nonsense. don't waste more time on a question you don't understand, and can't explain.

If you don't understand the question - and it's pretty clear - you need to talk to your tutor and get them to explain it to you in terms you can understand. Until you understand the question, you have no hope whatsoever of understanding - or producing - any answer.

So go back to you tutor and discuss the problem with them. It may be that you are not the only student in your class to have problems with this homework in which case it needs to be improved as an assignment before you can be expected to complete it.
 
Share this answer
 
Comments
Padala Vamsi ujpNQUXGRi 19-Sep-20 2:37am    
This was my placement question and I tried to contact my tutor even and they didn't answered it correctly. So, if you know you can answer.
OriginalGriff 19-Sep-20 3:49am    
What is a "Placement question"?
I'm not familiar with the term ...
Dave Kreskowiak 19-Sep-20 11:49am    
If you're talking about a "placement exam" to gauge your skill level in a curriculum, why would think it would be a good idea to ask everyone else to explain this to you?

Being able to understand and break down problems is part of the test!
OriginalGriff 19-Sep-20 11:56am    
I'm guessing it's part of a job application ... could be wrong though.
Quote:
I tried to understand the question from 15th sep 2020 till now but, I am unable to understand the question.

This comes from a challenge site, they usually provide forums for users, they will probably be able to help you as they are working on same problem.
You forgot to give link to the problem.
Exact wording matters in those problem, but we gave no way to know what is the real question.
[Update]
Quote:
Now Alice wants to know the expected number of turns until K distinct elements are generated.

The problem is badly posed because it makes assumptions on the behavior of random.
One can as well assume that k is the answer for any input.
 
Share this answer
 
v2
Comments
Padala Vamsi ujpNQUXGRi 19-Sep-20 2:38am    
This was my placement question and I tried to contact my tutor even and they didn't answered it correctly. So, if you know you can answer.
You can search it online so that you will get to know whether this is from any challenge or not.
Patrice T 19-Sep-20 5:35am    
do you men interview question or exam questions ?
BillWoodruff 19-Sep-20 8:03am    
+5 for forensic expertise :)
Patrice T 19-Sep-20 8:17am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900