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)
Input Format
Output Format
Example Input/Output 1
Input
Output
Explanation
Example Input/Output 2
Input
Output
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