Today we will see the HackerRank Day 6 Solution in Python. The problem is named Let’s review which is part of 30 Days of code on HackerRank. Let’s get started!
Day 6: Let’s review Problem statement
We are given a string, S, of length N, that is indexed from 0 to N-1. Our task is to print its even-indexed and odd-indexed characters as two space-separated strings on a single line
Sample Input
1
Hackerrank
Sample Output
Hcern akrak
Explanation: The first string contains the ordered characters from even indices is Hcern, and the second string contains the ordered characters from odd indices is akrak.
You can solve the problem here.
HackerRank Day 6 Solution in Python
n=int(input()) for i in range(n): #Get Input string string=input() #Variable to store characters in even index even='' #Variable to store characters in even index odd='' for j in range(len(string)): #if index is even if j%2==0: even+=string[j] #if index is odd else: odd+=string[j] print("{} {}".format(even,odd))
Code Explanation
- First, get the input string and create two variables to store characters in even index and odd index
- Then iterate through the string and check the index
- If the index is even append the character to the even variable
- If the index is odd append the character to the odd variable
- Finally, print the values stored in the even and odd strings
Also Read:
- HackerRank Day 8 Solution in Python: Dictionaries and Maps
- HackerRank Day 7 Solution in Python: Arrays
- HackerRank Day 6 Solution in Python: Let’s review
- HackerRank Day 5 Solution in Python: Loops
- HackerRank Day 4 Solution in Python: Class vs Instance
- HackerRank Day 3 Solution in Python: Intro to Conditional Statements
- HackerRank Day 2 Solution in Python: Operators
- HackerRank Day 1 Solution in Python: Data Types
- HackerRank Day 0 Solution in Python: Hello World
- HackerRank Day 29 Solution in Python: Bitwise AND
- HackerRank Day 28 Solution in Python: RegEx, Patterns, and Intro to databases
- HackerRank Day 27 Solution in Python: Testing
- HackerRank Day 26 Solution in Python: Nested Logic
- HackerRank Day 25 Solution in Python: Running Time and Complexity
- HackerRank Day 24 Solution in Python: More Linked Lists
- HackerRank Day 23 Solution in Python: BST Level Order Traversal
- HackerRank Day 22 Solution in Python: Binary Search Trees
- HackerRank Day 20 Solution in Python: Sorting
- HackerRank Day 19 Solution in Python: Interfaces
- HackerRank Day 18 Solution in Python: Queues and Stacks
- HackerRank Day 17 Solution in Python: More Exceptions
- HackerRank Day 16 Solution: Exceptions – String to Integer
- HackerRank Day 15 Solution in Python: Linked List
- HackerRank Day 13 Solution in Python: Abstract Classes
- HackerRank Day 14 Solution in Python: Scope
- HackerRank Day 12 Solution in Python: Inheritance
- HackerRank Day 11 Solution in Python: 2D Arrays
- HackerRank Day 10 Solution in Python: Binary Numbers