Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Fix SwiftUI Login Timeout Bug

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Fix SwiftUI Login Timeout Bug. Start with the requirements on the right.

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.

Problem

Debug a failing login screen flow where two views modify a shared AuthenticationManager and SessionService: track down why the 100ms verification timeout is never triggered due to @Published reactive updates on passwordAttempts causing view redraws, and fix it to allow successful authentication.

Asked in the Take Home / Practical Debugging Test stage. Task 3 of the 90-minute timed debugging test.

Problem

You are given a simplified login flow with shared mutable state. Implement the fix so the verification timeout always runs once per login attempt, even if reactive UI updates cause the view to redraw.

Function Contract

Implement fix_login_flow(passwordAttempts, events) and return whether authentication succeeds.

  • passwordAttempts: list of integers representing failed attempts over time
  • events: list of strings representing UI and service events in order
  • Return: True if login completes successfully, otherwise False

Constraints

  • 0 <= len(passwordAttempts) <= 10^4
  • 0 <= len(events) <= 10^4
  • events[i] is one of "submit", "redraw", "timeout", "success", "failure"
  • The fix must be robust to repeated reactive redraws
  • The solution should run in linear time

Function Signature

def fix_login_flow(passwordAttempts, events):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output