Techgig Xoriant Codecrackers - Top Talent Hunt challenge solution


The Slippery Pole (100 Marks)

Baba is partying hard and drinking hard drinks as his friend Vipul has won a big Coding Contest. It has been several hours and now he is totally drunk. He is out of his senses and has started to climb a pole. The rest of the people are trying to get him down but his dazed mind is unable to react and he is therefore not listening to anyone. The pole is long and slippery. The drinks were super hard and the hangover is going to be for days. Vipul is enjoying, laughing and observed that Baba slips down Y metre in the night and climbs X metre in the day time.

Now, he wants to know after how many days will Baba be at the top of the slippery pole, if the length of the pole is N metre. Since he is out too, you have to find the answer for him.

Input Format

The first line of input consists of numbers of test cases, T

Next T lines each consists of three space-separated integers X, Y and N.


1<= T <=100

1<= N <=10000000

1<= Y < X <=N

Output Format
For each test case, print the number of days Baba will take to reach at top of the pole in a separate line.

Sample TestCase 1
6 2 10
4 3 10

Solution in Python3:

def main():

    # Take input from the user by using the input() function and int() for integer
    testCase = int(input())

    # iterate the while loop for taking input number of time according to number of the testcases 
    while testCase>0:

        # Now Take the input using map and list function
        value = list(map(int,input().strip().split()))

        # divide the list according to the variable
        up = value[0
        down = value[1]
        poleLength = value[2

        # Now take the variable result = 1 for result
        result = 1

        # And another variable index that help to while loop to iterate according to our condition
        index = 0

        # Now iterate the while loop 
        while index<=poleLength:

            # Then we will update the index to +up
            index = index + up

            # And then we will check the index is equal to the polelength or not 
            if index >= poleLength:
            # If index is not equal to the polelength then continued our process that - dowm to the index
                result+=1  # +1 to the result



If you want to attempt this coding challenge then click this
Next Post Previous Post
No Comment
Add Comment
comment url