Swap First & Third Parts - Nth Character

 Coding Problem Keys 

 Swap First & Third Parts - Nth Character 

 Problem Statement 

The program must accept a string S and an integer N as the input. The program must divide the string S into three equal parts and swap the first and third parts. Then the program must print the Nth character when the modified string is repeated infinite number of times as the output.

Note: The length of S is always divisible by 3.

 Boundary Condition(S) 

3 <= Length of S <= 99
1 <= N <= 10

 Input Format 

The first line contains S.
The second line contains N.

 Output Format 

The first line contains a character from modified string S.

 Example Input/Output 1 

 Input 

SkillRack
7

 Output 

S

 Explanation 

After swapping the first and third parts in the string S, it becomes ackllRSki.
Now the 7th character in the modified string is S.
Hence the output is S.

 Example Input/Output 2 

 Input 

MONKEY
145

 Output 

E

 Note: Max Execution Time Limit: 500 millisecs 

 Solution 

 Programming Language: Python 3 Language 

s=input().strip()
n=int(input())
k=len(s)
s=s[-k//3:]+s[k//3:-k//3]+s[:k//3]
while(n-k>0):
    n=n-k
print(s[n-1])

# Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Next Multiple of X after N

Sum - Remove Last Occurring Zero

Maximum LCM of Adjacent Pair

Four Integers

Array Frequency Equals Value

Sort N Strings - Descending Order