Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Complex Coding Tasks: Recursion and More
00:00
5 left

Complex Coding Tasks: Recursion and More

HardPython

Problem

You're a software engineer at RTX working on ground-side telemetry decoding for a sensor payload. Frames arrive over a serial link as raw bytes; a small C module validates each frame, decodes a big-endian sensor reading, accumulates a checksum recursively, and tracks the largest reading seen so far. In bench testing the decoder either hangs, crashes, or reports readings that don't match what the test rig actually sent.

#include <stdint.h>

#define FRAME_SIZE 8
#define IS_VALID_FRAME(f) f[0] == 0xAA && f[1] == 0x55

int32_t bytes_to_int32_be(uint8_t *bytes) {
    return (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3];
}

int checksum_recursive(uint8_t *frame, int index) {
    if (index == FRAME_SIZE) {
        return 0;
    }
    return frame[index] + checksum_recursive(frame, index);
}

int32_t find_max_reading(int32_t *readings, int count) {
    int32_t max = 0;
    for (int i = 0; i < count; i++) {
        if (readings[i] > max) {
            max = readings[i];
        }
    }
    return max;
}

void process_telemetry_frame(uint8_t *frame, int32_t *readings_out, int *count_out) {
    if (IS_VALID_FRAME(frame) == 0) {
        return;
    }

    int32_t reading = bytes_to_int32_be(&frame[2]);
    readings_out[*count_out] = reading;
    *count_out = *count_out + 1;
}

Find every bug in this program: there's a macro-expansion bug, a recursion bug, an endianness/casting bug, and a couple of logic bugs around the max-value and buffer tracking. Walk through each one, exactly how it manifests, and how you'd fix it.

Use audit_decoder(source_code) and return the findings in source order as a list of objects containing bug, manifestation, and fix. The supplied source text is the decoder shown above.

Constraints

  • source_code is a string identifying the supplied decoder source
  • Return exactly five findings
  • Findings must be ordered by the first appearance of each defect
  • Each finding must contain bug, manifestation, and fix

Function Signature

def audit_decoder(source_code):
Interviewer

Your question is Complex Coding Tasks: Recursion and More. 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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.