2 min to read
HackerRank 30 Days of Code Solution Day 6: Let's Review
In this tutorial, we will guide you through the process of solving the Day 6: Let's Review
programming problem from HackerRank’s 30 Days of Code
challenge required basic knowledge of string manipulation and loops in programming.
In this article, we will understand the use of loops in programming.
Disclaimer: We encourage you to solve this challenge yourself before reading our tutorial. We have provided a detailed explanation of the problem and our solutions to help you check your work.
Hackerrank 30 days of code - Day 6: Let’s Review
It’s part of hackerrank’s 30 days of code. A series of 30-day programming challenges. Where you can learn new programming languages by solving the coding challenges.
Problem Statement and Explanation
Based on the given string, separate the string into two parts based on the following conditions:
- The first part will contain the characters at the even indices.
- The second part will contain the characters at the odd indices.
Input Format
- The first line has number of test cases (
T
) - Next
T
lines contain a string of lengthS
Operators Hackerrank solution in Python
Operators Hackerrank solution in JavaScript
Operators Hackerrank solution in C++
Explanation of the solution
- The string is split into lines using the split
('\n')
method. - The loop iterates over the lines, starting from the second line.
- Each line is split into words using the
split('')
method. - Two empty strings,
even
andodd
, are created. - The loop iterates over the words in the line, starting from the first word.
- If the current index is
even
, the word is appended to theeven
string. - Otherwise, the word is appended to the
odd
string. - The concatenation of the
even
andodd
strings is printed to the console.
Suppose we have a string s = "CodePerfectPlus"
. We can split the string into two parts based on the following conditions:
- The first part will contain the characters at the even indices -
CdPretls
- The second part will contain the characters at the odd indices -
oeefcPu