Given string str of size N, the task is to remove the characters present at odd indices (0-based indexing) of a given string.
Input: str = “abcdef”
The characters ‘b’, ‘d’ and ‘f’ are present at odd indices, i.e. 1, 3 and 5 respectively. Therefore, they are removed from the string.
Input: str = “geeks”
Approach: Follow the steps below to solve the problem:
- Initialize an empty string, say new_string, to store the result.
- Traverse the given string and for every index, check if it is even or not.
- If found to be true, append the characters at those indices to the string new_string.
- Finally, after complete traversal of the entire string, return the new_string.
Below is the implementation of the above approach:
Time Complexity: O(N)
Auxiliary Space: O(N)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Replace even-indexed characters of minimum number of substrings to convert a string to another
- Remove odd frequency characters from the string
- Minimize replacements or swapping of same indexed characters required to make two given strings palindromic
- Minimum cost to remove the spaces between characters of a String by rearranging the characters
- Program to print product of even and odd indexed elements in an Array
- Remove characters from the first string which are present in the second string
- Remove minimum characters from string to split it into three substrings under given constraints
- Find value after N operations to remove N characters of string S with given constraints
- Remove characters from given string whose frequencies are a Prime Number
- Subsequences generated by including characters or ASCII value of characters of given string
- Remove all non-alphabetical characters of a String in Java
- How to remove all non-alphanumeric characters from a string in Java
- Remove even frequency characters from the string
- Remove characters from string that appears strictly less than K times
- Number of ways to remove a sub-string from S such that all remaining characters are same
- Remove characters from a String that appears exactly K times
- Remove all duplicate adjacent characters from a string using Stack
- Remove uppercase, lowercase, special, numeric, and non-numeric characters from a String
- Remove all characters other than alphabets from string
- Min flips of continuous characters to make all characters same in a string
Improved By : sanjoy_62