Detect anagram in linked list

Last updated: March 21, 2026

Quick Overview

Given a linked list of characters, write a function to determine if any contiguous subsequence of the linked list is an anagram of a given string. The function should return true if such an anagram exists, and false otherwise. The input will consist of the head of the linked list and the target string, and the output should be a boolean value.

Supabase
Coding & Algorithms
Machine Learning Engineer
Supabase
March 21, 2026
Machine Learning Engineer
Onsite
Coding & Algorithms
Medium

30

6

3,187 solved


Given a linked list of characters, write a function to determine if any contiguous subsequence of the linked list is an anagram of a given string. The function should return true if such an anagram exists, and false otherwise. The input will consist of the head of the linked list and the target string, and the output should be a boolean value.

This coding problem is frequently asked during Onsite at Supabase. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Supabase expects candidates to write production-quality code, not just solve the puzzle.

What the Interviewer Expects
  • Recognize the underlying problem pattern (sliding window, two pointers, BFS/DFS, etc.)
  • Discuss multiple approaches and trade-offs before coding
  • Implement an optimal solution with clean, production-quality code
  • Handle all edge cases including boundary conditions and invalid input
  • Optimize both time and space complexity with clear justification
  • Test your solution systematically with well-chosen examples
Key Topics to Cover
Common algorithm patterns (sliding window, two pointers, BFS/DFS)
Edge cases and input validation
Sorting and searching
Binary search and divide and conquer
Dynamic programming and memoization
Graph algorithms and traversal
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you parallelize this solution?
  • What if the input doesn't fit in memory?
  • Can you optimize the space complexity of your solution?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Problem Analysis

To determine if any contiguous subsequence of a linked list of characters is an anagram of a given string, we can leverage the sliding window pattern. This approach is applicable here because we need ...

Approach
  1. Character Frequency Count: First, we will create a frequency count (hash map or array) of the characters in the target string. This will help us identify what constitutes an anagram.
  2. **Slid...

Submit Your Answer
Markdown supported

Related Questions