Now you are given an array of a characters (both ASCII and Kanji) and,
an index into the array. The index points to the start of some character.
Now you need to write a function to do a backspace (i.e. delete the
character before the given index).
Answer / Chand Mohmmad
In C, you can implement this by keeping track of the current position and maintaining a counter for the number of characters that have been skipped due to backspaces. When encountering a backspace, increment the counter and decrement the current position. Here's some pseudo code:
```c
function backspace(char arr[], int n, int k) {
int i = k - 1; // starting point after backspace
int countBackspaces = 0; // number of backspaces encountered
while (i >= 0 && countBackspaces > 0) {
if (arr[i] == '') {
countBackspaces--;
} else if (countBackspaces > 0) {
i--;
countBackspaces--;
} else {
break;
}
}
// Move the characters from the position after the backspace to the original position
for (int j = i + 1; j < n; j++) {
arr[i] = arr[j];
i++;
}
}
```
| Is This Answer Correct ? | 0 Yes | 0 No |
Is sorting a math skill?
What is the Difference between sax and dom parser?
How do you find the complexity of a bubble sort?
What is the need of sorting?
Is array a collection?
What is meant by strongly connected in a graph?
Q#1: An algorithm is made up of 2 modules M1 and M2.If order of M1 is F(n) and order of M2 is g (n) then what is the order of the algorithm. Q # 2 : How many binary trees are possible with 3 nodes? with 4 nodes?
State the difference between persistent and ephemeral data structure?
What is the default capacity of hashmap?
Tell me the difference between structure and array?
Given M x N matrix with sorted elements row wise and column wise, find elements?
What does arraylist remove do?