Remove All Occurrences of a Character from a String

Given a string str and a character 'X', write a function to remove all occurrences of 'X' from the given string.

If the character 'X' doesn't exist in the input string, the input will remain unchanged.

Input:

The first line of input contains a string without any leading and trailing spaces.
The second line of input contains a character(X) without any leading and trailing spaces.

Output:

The only line of output prints the updated string.

Example:

Input:
inputString
X
Output:
inputStringWithoutX

Constraints:

  • 0 <= N <= 106, where N is the length of the input string.
  • Time Limit: 1 second

Note:

You are not required to print anything explicitly; it has already been taken care of.

AnswerBot
4mo

Create a function to remove all occurrences of a given character from a string.

  • Iterate through the string character by character and build a new string excluding the specified character.

  • Use a StringBu...read more

Help your peers!
Select
Add answer anonymously...

Capgemini Engineering Software Engineer interview questions & answers

A Software Engineer was asked Q. Given an array of integers nums and an integer target, return indices of the two...read more
A Software Engineer was asked Q. Given an array of characters, find the first non-repeating character in the arra...read more
A Software Engineer was asked Q. What is destructuring in JavaScript?

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. Given an array of characters, find the first non-repeating character in the arra...read more
A Software Engineer was asked Q2. What is destructuring in JavaScript?
A Software Engineer was asked Q3. Is there an MCQ-based technical test in Round 1?
Capgemini Engineering Software Engineer 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