
Asked in Nagarro
Remove String from Linked List Problem
You are provided with a singly linked list where each node contains a single character, along with a string 'STR'. Your task is to remove all occurrences of the string 'STR' from the linked list.
Explanation:
Start checking for the string 'STR' occurrences from the end of the linked list, not from the beginning. Remove the occurrences and ensure that you check for any new formations of 'STR' after removing elements.
Input:
The first line contains an integer 'T' representing the number of test cases. Each test case consists of two lines: the first line contains the elements of the singly linked list as characters not separated by space, and the second line contains the string 'STR'.
Output:
For each test case, return the head of the linked list after removing the specified string occurrences.
Example:
Input:
T = 1
Linked List: a b a b a
STR: aba
Output:
a b
Constraints:
1 <= T <= 10
0 <= N <= 10^3
0 <= K <= 10^2
- Where 'N' is the size of the singly linked list and 'K' is the size of the string.
- Time limit: 1 second
Note:
You don't need to print the output, as it is handled for you. Just implement the relevant function.

AnswerBot
4mo
Remove all occurrences of a given string from a singly linked list by starting from the end of the list.
Traverse the linked list from the end to the beginning to efficiently remove the string occurren...read more
Help your peers!
Add answer anonymously...
Top Associate Software Engineer Interview Questions Asked at Nagarro
Q. Which platform do you use for coding?
Q. Given an array of size n containing numbers from 1 to n with one number missing,...read more
Q. What are some real-life applications of data structures?
Interview Questions Asked to Associate Software Engineer at Other Companies
Top Skill-Based Questions for Nagarro Associate Software Engineer
C++ Interview Questions and Answers
300 Questions
Data Structures Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

