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.
Be the first one to answer
Add answer anonymously...
Top Nagarro Associate Software Engineer interview questions & answers
Popular interview questions of Associate Software Engineer
Top HR questions asked in Nagarro Associate Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app