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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
C Code Problems
00:00
5 left

C Code Problems

HardPython

Problem

Cisco's switch firmware team parses incoming configuration packets on a management port before applying them to a device. Below is the packet-parsing routine a contractor wrote for a new line of access switches, lightly trimmed for review.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
    char device_name[16];
    int  port_count;
    unsigned char *payload;
} SwitchPacket;

SwitchPacket *parse_packet(const char *raw, int raw_len, const char *name) {
    SwitchPacket *pkt = malloc(sizeof(SwitchPacket));
    strcpy(pkt->device_name, name);

    pkt->payload = malloc(raw_len);
    int checksum;
    for (int i = 0; i <= raw_len; i++) {
        pkt->payload[i] = raw[i];
        if (raw[i] == 0xFF) {
            checksum = raw[i] ^ checksum;
        }
    }

    int remaining = raw_len - 20;
    if (remaining < pkt->port_count) {
        free(pkt->payload);
        return NULL;
    }

    return pkt;
}

What problems do you see in this code? Explain each one, how it would actually surface on a real management port, and what you would change.

Implement review_parser(source), which returns the detected issue labels in the order defined by the reference solution. The input is a C/C++ source string, and the output is a list of strings.

Constraints

  • source is a non-null string containing C or C++ source text
  • Return issue labels in the reference-check order
  • Each issue label appears at most once
  • Use only the Python standard language features

Function Signature

def review_parser(source):
Interviewer

Your question is C Code Problems. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.