Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

Consecutive Losses

Problem Description

India and Pakistan are playing a bilateral series of A matches. Now, you know that India won exactly B matches. We know that there are ACB ways in which India could win B out of the A matches played. Here NCR is the number of ways to choose R objects out of N objects. 

Having known that we want to know the number of possible results in which the maximum consecutive number of matches lost by India is exactly K.
We need to find that count for all K from 1 to A-B. Since the answer can be large, calculate it modulo 109 + 7.



Problem Constraints

1 <= B < A <= 5 x 105



Input Format
The two arguments are integers A and B, denoting the total number of matches played and matches won by India respectively.


Output Format

Return an array of length A - B, the ith element denotes the number of possible results in which maximum consecutive losses is exactly equal to i.

Since the answer can be large, calculate it modulo 109 + 7.



Example Input

Input 1:

  A : 5
  B : 2

Input 2:

  A : 4
  B : 1



Example Output

Output 1:

  [1, 6, 3]

Output 2:

  [0, 2, 2]



Example Explanation

Explanation 1:

  Let's denote a win by W and a defeat by L.
  So, possible number of ways in which India could win 2 out of 5 matches are-
  1.  WWLLL - Maximum 3 consecutive losses
  2.  WLWLL - Maximum 2 consecutive losses
  3.  WLLWL - Maximum 2 consecutive losses
  4.  WLLLW - Maximum 3 consecutive losses
  5.  LWWLL - Maximum 2 consecutive losses
  6.  LWLWL - Maximum 1 consecutive loss
  7.  LWLLW - Maximum 2 consecutive losses
  8.  LLWWL - Maximum 2 consecutive losses
  9.  LLWLW - Maximum 2 consecutive losses
  10. LLLWW - Maximum 3 consecutive losses

Explanation 2:

  Possible outcomes are- 
  1. WLLL - Maximum 3 consecutive losses
  2. LWLL - Maximum 2 consecutive losses
  3. LLWL - Maximum 2 consecutive losses
  4. LLLW - Maximum 3 consecutive losses



NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.
Start solving Consecutive Losses on Interview Code Editor
Hints
  • Hint 1
  • Solution Approach
  • Complete Solution

Discussion


Loading...
Click here to start solving coding interview questions
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
Select an option *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Graduation Year *
Graduation Year *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test