Remove Character from String Problem Statement

Given a string str and a character 'X', develop a function to eliminate all instances of 'X' from str and return the resulting string.

Input:

The first line contains a string without leading or trailing spaces.
The second line contains a character 'X' without leading or trailing spaces.

Output:

The output is a single line displaying the modified string.
Example:
Input:
hello world
o
Output:
hell wrld

Constraints:

  • 0 <= N <= 10^6, where N is the length of str.
  • Process should complete within 1 second.
Note:
No need to explicitly print anything; assume that all necessary output operations have been handled.
AnswerBot
4mo

Develop a function to remove all instances of a given character from a string.

  • Iterate through the string character by character and skip the character to be removed.

  • Build a new string by appending cha...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Expedia Group

Q. Knight Probability in Chessboard Calculate the probability that a knight remains...read more
Q. Binary Tree to Doubly Linked List Transform a given Binary Tree into a Doubly Li...read more
Q. Find Duplicates in an Array Given an array ARR of size 'N', where each integer i...read more
Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits