Select an Object by a Dynamic Integer Field

Quick Overview

Implement and explain a function that receives a list of objects whose values are integers, a field name, and a mode `MIN` or `MAX`. Make the API or object boundaries explicit, then cover invariants, edge cases, testing strategy, and operational trade-offs.

Select an Object by a Dynamic Integer Field

Company: Bridge

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

Implement and explain a function that receives a list of objects whose values are integers, a field name, and a mode `MIN` or `MAX`. Return the object containing that field whose value is best for the requested mode. Objects missing the field are ignored. If no object contains it, return no result. If multiple objects tie, return the earliest one in the input. Do not mutate the objects. ### Constraints & Assumptions - Field names are strings and present values are integers. - The list may be empty and objects may have different fields. - The implementation should make one pass and use constant auxiliary state. ### Clarifying Questions to Ask - Should a present `null` be treated as missing or invalid? - What deterministic tie rule is required? - Should malformed noninteger values fail the entire call or be skipped? ```hint Track presence separately Initializing the best value to zero is incorrect when every candidate is negative or the field is absent. ``` ### What a Strong Answer Covers - One-pass selection, missing-field handling, mode validation, and stable ties. - A clear return type and error policy. - Tests for empty input, negative values, duplicate extrema, absent keys, and invalid mode. ### Follow-up Questions - How would you return all tied objects? - How would the design change for a nested field path? - When would a reusable comparator be preferable to a mode flag?

Quick Answer: Implement and explain a function that receives a list of objects whose values are integers, a field name, and a mode `MIN` or `MAX`. Make the API or object boundaries explicit, then cover invariants, edge cases, testing strategy, and operational trade-offs.

|Home/Software Engineering Fundamentals/Bridge
Bridge logo
Bridge
Jul 30, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenSoftware Engineering Fundamentals
0
0

Implement and explain a function that receives a list of objects whose values are integers, a field name, and a mode MIN or MAX. Return the object containing that field whose value is best for the requested mode.

Objects missing the field are ignored. If no object contains it, return no result. If multiple objects tie, return the earliest one in the input. Do not mutate the objects.

Constraints & Assumptions

  • Field names are strings and present values are integers.
  • The list may be empty and objects may have different fields.
  • The implementation should make one pass and use constant auxiliary state.

Clarifying Questions to Ask Guidance

  • Should a present null be treated as missing or invalid?
  • What deterministic tie rule is required?
  • Should malformed noninteger values fail the entire call or be skipped?

What a Strong Answer Covers Guidance

  • One-pass selection, missing-field handling, mode validation, and stable ties.
  • A clear return type and error policy.
  • Tests for empty input, negative values, duplicate extrema, absent keys, and invalid mode.

Follow-up Questions Guidance

  • How would you return all tied objects?
  • How would the design change for a nested field path?
  • When would a reusable comparator be preferable to a mode flag?
Loading comments...