Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Parse Machine Codes to Typed Objects
00:00
5 left

Parse Machine Codes to Typed Objects

EasyPython

Problem

Write a parser that converts machine codes (e.g. 123) into corresponding typed objects via an enum (TYPE1, TYPE2, TYPE3...).

Asked in the phone screen stage. The main prompt was points-walled; only the clarifying example was visible.

Input and Output

Implement parse_machine_codes(codes). codes is a list of integers. Code 123 maps to TYPE1, 456 maps to TYPE2, and 789 maps to TYPE3. Unknown codes map to UNKNOWN. Return a list of objects represented as dictionaries with code and type fields, preserving input order.

Constraints

  • 0 <= len(codes) <= 10^4
  • Every input element is an integer
  • Known codes are 123, 456, and 789
  • Unknown codes must be represented as UNKNOWN
  • Preserve duplicate codes and input order

Function Signature

def parse_machine_codes(codes):
Interviewer

Your question is Parse Machine Codes to Typed Objects. 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.