KEEP SWAPPING

Given a string of lowercase alphabets A of size N and two integers B and C.

You have to perform B swaps, Where ith swap = swap(A[i%N], A[ (i + C)%N ]).

Return the final string A after B swaps.

NOTE: String A is 0 based indexed.

NOTE: Swaps are 1 based indexed.



Input Format

The first argument given is the string A.
The second argument given is the integer B.
The third argument given is the integer C.

Output Format

Return the final string A after B swaps.

Constraints

1 <= N <= 10^5
1 <= B <= 10^8
1 <= C <= N

For Example

Input 1:
    A = "interviewbit"
    B = 4
    C = 3
Output 1:
    A = "irvietenwbit"
Explaination 1:
    After swap 1: swap(A[1%12], A[(1 + 3)%12]) A = "irtenviewbit"
    After swap 2: swap(A[2%12], A[(2 + 3)%12]) A = "irventiewbit"
    After swap 3: swap(A[3%12], A[(3 + 3)%12]) A = "irvinteewbit"
    After swap 4: swap(A[4%12], A[(4 + 3)%12]) A = "irvietenwbit"	
Input 2:
    A = "raman"
    B = 1
    C = 4
Output 2:
    A = "arman"
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 doubt? Checkout Sample Codes for more details.
Start solving KEEP SWAPPING on Interview Code Editor
Sign Up
to access hints and editorial solutions for KEEP SWAPPING

Discussion


Loading...
Click here to start solving coding interview questions