Given a string s, a character c and an integer position pos, the task is to insert the character c into the string s at the specified position pos.
Examples:
Input: s = "Geeks", c = 'A', pos = 3
Output: GeeAksInput: s = "HelloWorld", c = '!', pos = 5
Output: Hello!World
[Approach-1] Using Built-In Methods
We will use library methods like string insert in C++, StringBuilder insert in Java and String Slicing in Python.
// C++ program to insert a character at specific
// position using Built in functions
#include <bits/stdc++.h>
using namespace std;
string insertChar(string &s, char c, int pos) {
// Insert character at specified position
s.insert(s.begin() + pos, c);
return s;
}
int main() {
string s = "Geeks";
cout << insertChar(s, 'A', 3);
return 0;
}
// Java program to insert a character at specific
// position using Built in functions
class GfG {
static String insertChar(StringBuilder sb, char c, int pos) {
// Insert character at specified position
sb.insert(pos,