learn kro favicon img

Day 6: Let’s Review | HackerRank Solution

Hello coders, today we are going to solve Day 6: Let’s Review HackerRank Solution in C++Java and Python.

Objective

Today we will expand our knowledge of strings, combining it with what we have already learned about loops.

Task

Given a string, S, of length N that is indexed from 0 to – 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.

Example

s = adbecf

Print abc def

Input Format

The first line contains an integer, T (the number of test cases).
Each line i of the T subsequent lines contain a string, S.

Constraints

For each String Sj (where <= j <= T – 1), print Sj‘s even-indexed characters, followed by a space, followed by Sj‘s odd-indexed characters.

Sample Input

Sample Output

Explanation

Test Case 0S = “Hacker”
S[0] = “H”
S[1] = “a”
S[2] = “c”
S[3] = “k”
S[4] = “e”
S[5] = “r”
The even indices are 02, and 4, and the odd indices are 13, and 5. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S‘s even indices (Hce), and the second string contains the ordered characters from S‘s odd indices (akr).

Test Case 1S = “Rank”
S[0] = “R”
S[1] = “a”
S[2] = “n”
S[3] = “k”
The even indices are 02 and 4, and the odd indices are 1, 3 and 5. We then print a single line of 2 space-separated strings; the first string contains the ordered characters from S‘s even indices (Rn), and the second string contains the ordered characters from S‘s odd indices (ak).

Solution – Day 6: Let’s Review

C++

Java

Python

# Enter your code here. Read input from STDIN. Print output to STDOUT

Disclaimer: The above Problem (Day 6: Let’s Review) is generated by Hacker Rank but the Solution in Provided by Learnkro. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *