![]() |
VOOZH | about |
Given string str, the task is to print the middle character of a string. If the length of the string is even, then there would be two middle characters, we need to print the second middle character.
Examples:
Input: str = "Java"
Output: v
Explanation:
The length of the given string is even.
Therefore, there would be two middle characters 'a' and 'v', we print the second middle character.Input: str = "GeeksForGeeks"
Output: o
Explanation:
The length of the given string is odd.
Therefore, there would be only one middle character, we print that middle character.
Approach:
Below is the implementation of the above approach:
o
Time Complexity: O(1)
Auxiliary Space: O(1)