Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Replace pi to 3.14

Easy Acceptance 75.00% Points 20.00

You are given a string s. Your task is to replace every occurrence of the substring "pi" with "3.14" using recursion only. You are not allowed to use loops or built-in replace functions. Return the modified string after all replacements.

Examples
Example 1

Example 1

Input: s = "pip"

Output: "3.14p"

Explanation: The substring "pi" is replaced with "3.14".

Example 2

Example 2

Input: s = "pipi"

Output: "3.143.14"

Explanation: Both occurrences of "pi" are replaced.

Example 3

Example 3

Input: s = "apple"

Output: "apple"

Explanation: Since "pi" is not present, the string remains unchanged.

Hints
Hint 1
N/A
Constraints
  • 1 = length of s = 105
  • The string contains lowercase English letters only
Companies
Visa Oracle Flipkart
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions