Find the Longest Run of One Character

Last updated: July 31, 2026

Quick Overview

The candidate is asked to write a function that finds the longest contiguous run of the same character in a given string.

Netflix
Coding & Algorithms
Software Engineer
Netflix
July 31, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

2

0

25 solved


The candidate is asked to write a function that finds the longest contiguous run of the same character in a given string.

This question is typically asked during the technical screen to evaluate the candidate's problem-solving skills and coding proficiency. The interviewer is looking for a clear understanding of string manipulation, algorithmic thinking, and the ability to write clean, efficient code. It also assesses how well the candidate can explain their thought process and handle edge cases.

What the Interviewer Expects
  • Clearly explain the approach before coding.
  • Handle edge cases such as empty strings or strings with no repeated characters.
  • Provide a clean and efficient implementation.
  • Discuss time and space complexity.
  • Test the solution with different input cases.
Key Topics to Cover
String Manipulation
Algorithm Design
Time Complexity
Edge Cases
Coding Best Practices
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 optimize your solution?
  • What would you do if the input string were very large?
  • Can you explain how your solution handles special characters?
Sharpen Your Skills on Codemia

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

Practice DSA Problems
Sample Answer
Approach

To solve the problem, we will iterate through the string while keeping track of the current character and its count. We will compare this count with the maximum count found so far. If we encounter a d...

Algorithm

Here’s a simple implementation of the algorithm in Python:

def longest_run(s): if not s: return 0 max_count = 1 current_count = 1 for i in range(1, len(s)): ...

Submit Your Answer
Markdown supported

Related Questions