
Asked in MAQ Software
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 specified string from a singly linked list by checking from the end of the list.
Traverse the linked list from the end to efficiently remove the specified string occurrences...read more
Help your peers!
Add answer anonymously...
Top Software Engineer Interview Questions Asked at MAQ Software
Q. How does hashing help in identifying duplicate values?
Q. What is the difference between span and div tags?
Q. Given an array and a number, determine whether the number can be generated using...read more
Interview Questions Asked to Software Engineer at Other Companies
Top Skill-Based Questions for MAQ Software Software Engineer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL 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

