N Characters Forward Reverse

 Coding Problem Keys 

 N Characters Forward Reverse 

 Problem Statement 

The program must accept a string S and an integer value N. Then the program must print the first N characters, then must print the next N characters in reverse direction and so on.

 Boundary Condition(S) 

1 <= Length of S <= 1000

 Input Format 

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

 Output Format 

The first line contains a string value.

 Example Input/Output 1 

 Input 

abcdefghijk
3

 Output 

abcfedghikj

 Explanation 

Here N is 3.
So abc is printed.
Then fed are reversed and printed.
Then ghi is printed.
The remaining characters kj are reversed and printed.

 Example Input/Output 2 

 Input 

mango
2

 Output 

magno

 Note: Max Execution Time Limit: 50 millisecs 

 Solution 

 Programming Language: Python 3 Language 

l=input().strip()
k=int(input())
c=0
for i in range(0,len(l),k):
    if(c%2!=0):
        print(l[i:i+k][::-1],end="")
    else:
        print(l[i:i+k],end="")
    c+=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

Function decimalToBinary - CTS Pattern

Words Starting with Upper Case

Occurrences of Sub in Parent

Interface Implementation - Pair

Flowchart Logic 047

Bank Account Balance

Reverse In Groups