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).



Now you are given an array of a characters (both ASCII and Kanji) and, an index into the array. The..

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

Post New Answer

More Data Structures Interview Questions

Is sorting a math skill?

1 Answers  


What is the Difference between sax and dom parser?

1 Answers  


How do you find the complexity of a bubble sort?

1 Answers  


What is the need of sorting?

1 Answers  


Is array a collection?

1 Answers  


What is meant by strongly connected in a graph?

1 Answers  


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?

4 Answers  


State the difference between persistent and ephemeral data structure?

1 Answers  


What is the default capacity of hashmap?

1 Answers  


Tell me the difference between structure and array?

1 Answers   NIIT,


Given M x N matrix with sorted elements row wise and column wise, find elements?

1 Answers   Expedia,


What does arraylist remove do?

1 Answers  


Categories