0
0
DSA Pythonprogramming~20 mins

String Traversal and Character Access in DSA Python - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Traversal Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of character access in a loop
What is the output of the following code snippet?
DSA Python
s = "hello"
result = []
for i in range(len(s)):
    if i % 2 == 0:
        result.append(s[i])
print(''.join(result))
Ahlo
Bel
Chello
Dheo
Attempts:
2 left
💡 Hint
Look at characters at even indexes only.
Predict Output
intermediate
2:00remaining
Output of negative indexing in string
What will be printed by this code?
DSA Python
s = "world"
print(s[-1] + s[-2] + s[-5])
Adlo
Bdlw
Cdwl
Dwrd
Attempts:
2 left
💡 Hint
Negative indexes count from the end starting at -1.
🔧 Debug
advanced
2:00remaining
Identify the error in string character access
What error does this code raise when executed?
DSA Python
s = "data"
for i in range(len(s)+1):
    print(s[i])
AIndexError
BTypeError
CSyntaxError
DNo error, prints all characters
Attempts:
2 left
💡 Hint
Check the range and valid indexes for string s.
Predict Output
advanced
2:00remaining
Output of slicing with step in string
What is the output of this code?
DSA Python
s = "algorithm"
print(s[1:8:2])
Alorm
Blghm
Clgih
Dloih
Attempts:
2 left
💡 Hint
Slice from index 1 to 7 with step 2.
🧠 Conceptual
expert
2:00remaining
Count of unique characters accessed in loop
Consider the code below. How many unique characters are printed?
DSA Python
s = "abracadabra"
seen = set()
for i in range(len(s)):
    if s[i] not in seen:
        print(s[i], end='')
        seen.add(s[i])
A6
B7
C5
D8
Attempts:
2 left
💡 Hint
Count distinct characters in the string.