Remove Occurrences of Character from String

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

If the character X does not exist in the input string, the string should remain unchanged.

Example:

Input:
str = 'hello world'
X = 'o'
Output:
'hell wrld'

Constraints:

  • 0 <= N <= 10^6, where N is the length of the string.
  • Time Limit: 1 second
AnswerBot
4mo

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

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

  • Use string manipulation functions to ...read more

Help your peers!
Select
Add answer anonymously...

Hewlett Packard Enterprise Software Developer interview questions & answers

A Software Developer was asked Q. Given a string, return the character counts. For example, input 'aabbbc' should ...read more
A Software Developer was asked Q. Design a classroom management system.
A Software Developer was asked Q. How well can you adapt to changes in technology used for a project? Explain your...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Given a string, return the character counts. For example, input 'aabbbc' should ...read more
A Software Developer was asked Q2. Design a classroom management system.
A Software Developer was asked Q3. How well can you adapt to changes in technology used for a project? Explain your...read more
Hewlett Packard Enterprise 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