cswork / OAOpen practice workspace

CommvaultOA #2

Count Ways to Travel Cities

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)DP BasicsPrefix & Ranges

In a country there are different cities and the cities marked with integer number starting from 1. And now you need to travel in the N cities with some following criteria.

  • You need to travel exactly N cities and you can start travelling from any of the cities
  • If you visit a city of number n, then the next city number will be more than or equal to 2n
  • And you are also given a number K and any city number can't more than K. Now you are given N and K, need to find how many ways you can travel the cities by keeping in mind the conditions given. And return the answer in module 1000000007 as the answer will be very large. Function Description Complete the function countWaysToTravelCities in the editor. countWaysToTravelCities has the following parameters: N: an integer, the number of cities to travel K: an integer, the maximum city number allowed Returns int: the number of ways to travel the cities modulo 1000000007

Example 1

Input:

N = 3
K = 10

Output:

TO-DO

Explanation: Some of the valid city paths will be -

  • 1-2-4
  • 1-3-6
  • 1-4-8 There are more ways to travel the cities, but these are just a few examples.

Editorial

Loading solution…