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
Coding & Algorithms
Software Engineer
Figma
May 17, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

25

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
Hash maps and frequency counting
Tree structures and recursion
Graph algorithms and traversal
Edge cases and input validation
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
  • 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 Problems
Sample 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:

  1. Initialize a variable max_length to keep track of the maximum consecutive length found.
  2. Initialize a ...

Submit Your Answer
Markdown supported

Related Questions