Codersbit problem

Given a string of lowercase alphabets A and two integers B and C.
length of string N <= 1e5
B <= 1e11
C <= N

for(i=0;i<=B;i++) swap(A[i%N],A[(i+C)%N]);

print final string…

Not able to do this question, can anyone help how to do this problem

I have a solution but it is unproven and totally based on observation.
First, do what is being told in the question for string = “0123456789” and C = 3
Observe the string obtained after each iteration. Found the pattern?
Well, for any string, you will find it is divided into two sets, the elements of string indexed 0 to c-1 will be always together (in some permutation) and other set of remaining characters will have a regular pattern. Observe the period of permutation of string [0…c-1] and observe the period of it’s repetition. You will have the answer!

4 Likes

Hey! How did get to participate in Codersbit? I registered for it and its saying that tentative date September. Any idea how to participate there?
P.S. : Our college does not have an ambassador of Codersbit

1 Like

same problem bro sayan_000

1 Like

It was mentioned clearly on their website that it starts in July, did you get mail saying it is in september? https://www.interviewbit.com/codersbit/

No, I didn’t get any mail. After registration only the link that you have given shows that “you are already registered for this contest. Tentative date will be 1st September”. But as per their schedule is concerned, the contest will end within august. :frowning:

Okay, but since you are registered, you should be able to compete in coming rounds (if any)

How do you consider the corner case while swapping ith and jth index when j>N (N: the length of original string). the string[0…c-1] wont be together ?..How did you manage to find the Bth permutation…i.e., is there any repeating pattern ?

1 Like

It will always be together cyclically. Print it and see for yourself.