Day 7 of My 30-Day Coding Challenge on HackerRank
Day 7 was all about strings and loops—combining two important concepts to solve a character-based problem.
Today’s challenge focused on separating the even-indexed and odd-indexed characters of a string.
Problem Overview
Today’s challenge focused on:
Understanding string indexing
Using loops with strings
Separating characters based on position
Handling multiple test cases
We were given a string s and asked to print:
All characters at even indices
All characters at odd indices
Both outputs had to be printed on the same line separated by a space.
Note: Indexing starts from
0, so index0is even.
My Solution
t = int(input())
for _ in range(t):
s = input()
even = s[::2]
odd = s[1::2]
print(even, odd)
What I Did Today
I learned how to:
Access string characters using indexes
Use slicing in Python
Handle multiple inputs using loops
Separate data based on conditions
Here’s the logic I followed:
1. Read number of test cases
2. For each string:
3. Get characters at even indexes
4. Get characters at odd indexes
5. Print both separated by space
🧠 What I Learned
Today’s key takeaways:
Strings can be accessed like arrays using indexes
Python slicing makes problems easier
s[::2]gets even-indexed characterss[1::2]gets odd-indexed charactersCombining loops + strings is powerful
Challenges Faced
Understanding index positions clearly
Remembering that indexing starts at
0Formatting output exactly as required
Why This Problem Matters
This problem helps in understanding:
String traversal techniques
Data filtering based on position
Efficient use of slicing in Python
These concepts are useful in text processing and coding interviews.
Sample Run
Input:
2
Hacker
Rank
Output:
Hce akr
Rn ak
Plan for Day 8
- Improve problem-solving speed
💬 Final Thoughts
Day 7 was a fun challenge that showed how useful string indexing can be.
Simple concepts like loops and slicing can solve problems efficiently when used correctly.
Let’s keep learning and improving
