Count maximum path in linked list
Last updated: May 17, 2026
Quick Overview
Given a singly linked list, write a function to count the maximum number of consecutive nodes that form a path with the same value. The function should take the head of the linked list as input and return an integer representing the length of the longest consecutive path.
Figma
May 17, 202625
10
1,465 solved
Given a singly linked list, write a function to count the maximum number of consecutive nodes that form a path with the same value. The function should take the head of the linked list as input and return an integer representing the length of the longest consecutive path.
Figma uses this problem in the Phone Screen to evaluate your algorithmic thinking. They expect you to discuss multiple approaches, analyze trade-offs between them, and implement the optimal solution with clean, readable code.
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What is the worst-case input for your solution?
- How would you modify your solution to handle streaming input?
- What if the input doesn't fit in memory?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
The problem requires us to traverse a singly linked list and count the maximum number of consecutive nodes that have the same value. This is a straightforward case of sequential traversal, where we ca...
Approach
We will implement a single pass algorithm to solve this problem. The steps are as follows:
- Initialize a variable
max_lengthto keep track of the maximum consecutive length found. - Initialize a ...