Title: Lucky Seven - Simple String Indexing
Problem Understanding:
We are given a string S of length 10.
Chef considers the 7th letter as lucky.
We need to print the 7th character in the string.
Important Concept:
In Python, indexing starts from 0.
So:
1st character β index 0
2nd character β index 1
β¦
7th character β index 6
Approach:
- Take input string S
- Print the character at index 6
Code:
s = input()
print(s[6])
Example:
Input: proceeding
Output: e
Explanation:
String = p r o c e e d i n g
Index = 0 1 2 3 4 5 6 7 8 9
7th character = index 6 = βeβ
Time Complexity:
O(1)
Space Complexity:
O(1)