Detect permutation in linked list

Last updated: July 26, 2025

Quick Overview

Given a linked list and a string representing a permutation, determine if any contiguous sublist of the linked list forms a permutation of the given string. The function should return true if such a sublist exists, and false otherwise. The linked list nodes contain single characters, and the string's length will dictate the size of the sublist to check.

Grafana Labs
Coding & Algorithms
Software Engineer
Grafana Labs
July 26, 2025
Software Engineer
Phone Screen
Coding & Algorithms
Medium

160

12

2,531 solved


Given a linked list and a string representing a permutation, determine if any contiguous sublist of the linked list forms a permutation of the given string. The function should return true if such a sublist exists, and false otherwise. The linked list nodes contain single characters, and the string's length will dictate the size of the sublist to check.

This coding problem is frequently asked during Phone Screen at Grafana Labs. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Grafana Labs 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
Binary search and divide and conquer
Hash maps and frequency counting
Graph algorithms and traversal
Time and space complexity analysis
Common algorithm patterns (sliding window, two pointers, BFS/DFS)
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 your solution change if the input was sorted?
  • Can you solve this iteratively instead of recursively (or vice versa)?
  • What happens if the input contains duplicates?
  • What is the worst-case input for 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

This problem can be effectively approached using the sliding window technique. The reason for this choice is that we need to check contiguous sublists of a linked list against a given permutation ...

Approach
  1. Convert the linked list to a string: Traverse the linked list to form a string representation of its characters. This will allow us to easily access the characters for comparisons.

  2. **Count ...


Submit Your Answer
Markdown supported

Related Questions