Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6379 |

@blackshadows | 6329 |

@mb1973 | 5358 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3357 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@ritiksethi21 | 1050 |

@aroranayan999 | 807 |

@RizulBansal | 685 |

@ashishtrehan002 | 538 |

@hemantgarg923 | 528 |

@simrangoyal | 526 |

@ronaldo77 | 520 |

@thanosagain | 505 |

@anishrajan | 505 |

@ssparteek470 | 495 |

@rahul2312 | 491 |

Complete Leaderboard |

Given two integers n and k, count the number of binary strings of length n where adjacent 1 appear k times.

**Example 1:**

**Input:**
n = 3 , k = 2
**Output:** 1
**Explanation: **Possible string is "111".

â€‹**Example 2:**

**Input**:
n = 5 , k = 2
**Output:** 6
**Explanation**: Possible strings are:
"00111" , "10111" , "01110"
"11100" , "11101" , "11011".

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **countStrings() **which accepts integers **n** and **k **as input parameter and returns the number of binary strings that satisfy the given condition.

**Expected Time Complexity: **O(n*k).

**Expected Auxiliary Space: **O(n*k).

**Constraints:**

1 <= n, k <= 10^{3}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Count binary strings

...