Replace Character Problem Statement

Given an input string S and two characters 'c1' and 'c2', your task is to replace every occurrence of the character 'c1' with the character 'c2' in the given string.

Input:

Line 1: Input String S
Line 2: Character c1 and c2 (separated by space)

Output:

Updated string

Example:

Input:
S = "hello world"
c1 = "l" c2 = "x"
Output:
"hexxo worxd"

Constraints:

  • 1 <= Length of String S <= 10^6
AnswerBot
4mo

Replace every occurrence of a character in a string with another character.

  • Iterate through the input string and replace 'c1' with 'c2' using string manipulation functions.

  • Return the updated string as ...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Accenture

Q. Describe the SOLID principles.
Q. What is the purpose of if __name__ == "__main__"?
Q. What is Hypertext Markup Language (HTML)?
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