Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Find Longest Error-Free Session
00:00
5 left

Find Longest Error-Free Session

MediumPython

Problem

Given a log of user interactions with an AI feature at Amplify HR, write a script to identify the longest session without errors. The input is a chronological list of dictionaries with session_id and boolean error fields. Return [session_id, interaction_count] for the longest session containing no errors. If multiple sessions tie, return the one whose first interaction appears earliest. Return ["", 0] when no error-free session exists.

Constraints

  • 0 <= len(log) <= 10^4
  • Each interaction is a dictionary with string key session_id and boolean key error
  • Every interaction belongs to exactly one session
  • The log is ordered chronologically
  • If no session is error-free, return ["", 0]

Function Signature

def longest_error_free_session(log):
Interviewer

Your question is Find Longest Error-Free Session. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.