PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Affirm

Determine winner in optimal-play card game

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving skills in game-theoretic optimal play and dynamic programming, including reasoning about maximum score difference, reconstruction of an optimal move sequence, and analysis of time and space complexity.

  • Medium
  • Affirm
  • Coding & Algorithms
  • Software Engineer

Determine winner in optimal-play card game

Company: Affirm

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Given a row of N cards with integer values (values may be positive, zero, or negative), two players alternately pick either the leftmost or rightmost card. Both play optimally to maximize their total sum. Implement a function winner_score(cards: List[int]) -> int that returns the maximum score difference (first − second). Then: - Explain your time and space complexity. - Modify the function to also return one optimal sequence of picks (as a list of indices). Constraints: 1 ≤ N ≤ 2000.

Quick Answer: This question evaluates algorithmic problem-solving skills in game-theoretic optimal play and dynamic programming, including reasoning about maximum score difference, reconstruction of an optimal move sequence, and analysis of time and space complexity.

Related Interview Questions

  • Determine Redeemable Promotion Offers - Affirm (medium)
  • Compute Available Offers per User - Affirm (easy)
  • Aggregate loans and match repayments - Affirm (medium)
  • Implement a timestamped map - Affirm (medium)
  • Detect fraud events and extract PII - Affirm (medium)
Affirm logo
Affirm
Jul 15, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
13
0

Given a row of N cards with integer values (values may be positive, zero, or negative), two players alternately pick either the leftmost or rightmost card. Both play optimally to maximize their total sum. Implement a function winner_score(cards: List[int]) -> int that returns the maximum score difference (first − second). Then:

  • Explain your time and space complexity.
  • Modify the function to also return one optimal sequence of picks (as a list of indices). Constraints: 1 ≤ N ≤ 2000.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Affirm•More Software Engineer•Affirm Software Engineer•Affirm Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.