Day 6 Let’s Review problem Statement
Given a string, S, of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line (see the Sample below for more detail).
Note: 0 is considered to be an even index.
The first line contains an integer, T(the number of test cases).
Each line i of the T subsequent lines contain a String, S.
For each String Sj (where 0<=j<=T-1), print Sj‘s even-indexed characters, followed by a space, followed by Sj‘s odd-indexed characters.
We first divide the string into even and odd number as we can see that in the string “Hacker“, ‘H’ is in even place and ‘a’ is in an odd place and so on. So our string is “Hacker” can be divided by even(H), odd(a), even(c), odd(k), even(e), and odd(r).
HackerRank Day 6 Solution in Python
# First we have to take the input of the number of Strings NumberOfStrings = int(input()) # for loop from 0 to the length of the String for i in range(0, NumberOfStrings): # Taking input from the User string = input() # The below line has two parts 1. string[::2] & 2. string[1::2]. # General format is [start:stop:step]. # 1. string[::2] basically means that start from 0 to the end of the String skipping 2 characters hence taking all even strings # 2. string[1::2] same as the above but we start from 1 and not 0 print(string[::2],string[1::2])