Autocoder

NXP Coding Round Questions with Solutions

Last updated 2026-11-19

Written and online tests for embedded roles ask for code that looks like firmware: parse a frame, compare timestamps that can wrap, simulate a scheduler, implement CAN bit stuffing. This page gives twelve practice problems in that style, each with a complete runnable solution, complexity and the common mistake.

They are practice problems in the style of topics such tests are commonly reported to include, not real papers. See NXP interview questions for the concept side and Bosch coding round questions for a related automotive flavour.

How to approach them

Think about the failure case first: a counter that wraps, a frame with a bad length, an empty buffer. Firmware has to keep working when the input is wrong, so handle it in the code and say so.

Use fixed-width unsigned types, name your constants, and keep functions small enough to test on a PC. State the complexity, even if it is trivial.

Hiring status

No sourced hiring facts for NXP are held on this site, so no dates, openings or packages are quoted. Use the company's own careers site.

NXP Coding Round Questions with Solutions: questions with worked answers

  1. 1

    Find which CAN frame wins arbitration among nodes that transmit at the same time.

    easy

    The frame with the numerically lowest identifier wins, since dominant zeros override recessive ones bit by bit. In Python, take the minimum. For IDs 0x2A0, 0x100 and 0x7FF the winner is 0x100. Time O(n), space O(1). Common mistake: choosing the highest ID, or comparing strings of hex digits instead of integers. Note that an 11-bit ID beats a 29-bit extended frame with the same base ID because of the IDE bit.

    python
    def winner(ids):
        return min(ids)
    
    print(hex(winner([0x2A0, 0x100, 0x7FF])))  # 0x100
  2. 2

    Apply CAN-style bit stuffing to a bit string.

    medium

    After five consecutive identical bits, insert the opposite bit; the inserted bit starts a new run. For "11111100000" the output is five 1s, a stuffed 0, the sixth 1, five 0s and a stuffed 1: 1111101000001. Time O(n), space O(n). Common mistake: not counting the stuffed bit toward the next run, or stuffing after four bits.

    python
    def stuff(bits):
        out, run, last = [], 0, None
        for b in bits:
            out.append(b)
            if b == last:
                run += 1
            else:
                run, last = 1, b
            if run == 5:
                s = '1' if b == '0' else '0'
                out.append(s)
                run, last = 1, s
        return "".join(out)
    
    print(stuff("11111100000"))  # 1111101000001
  3. 3

    Parse a serial frame [0xAA][len][payload...][checksum] and validate the checksum (sum of all bytes before it, modulo 256).

    medium

    Check the start byte, check that the buffer is long enough for len, add the header and payload bytes in an 8-bit accumulator and compare with the last byte. Return the payload length or an error. Time O(len), space O(1). Common mistake: trusting len without checking against the buffer size, which reads out of bounds on a corrupted frame.

    c
    #include <stdio.h>
    #include <stdint.h>
    #include <stddef.h>
    int parse(const uint8_t *f, size_t n) {
        if (n < 3 || f[0] != 0xAA) return -1;
        size_t len = f[1];
        if (n != len + 3) return -1;
        uint8_t sum = 0;
        for (size_t i = 0; i < len + 2; i++) sum += f[i];
        return sum == f[len + 2] ? (int)len : -2;
    }
    int main(void) {
        uint8_t ok[] = {0xAA, 0x02, 0x10, 0x20, 0x00};
        ok[4] = (uint8_t)(0xAA + 0x02 + 0x10 + 0x20);
        uint8_t bad[] = {0xAA, 0x02, 0x10, 0x20, 0x00};
        printf("%d %d\n", parse(ok, 5), parse(bad, 5)); /* 2 -2 */
        return 0;
    }
  4. 4

    Compare a free-running 32-bit tick counter with a deadline in a way that survives wrap-around.

    medium

    Compute the difference as unsigned, then reinterpret it as signed: (int32_t)(now - deadline) >= 0 means the deadline has passed, as long as the two times are less than 2^31 ticks apart. A plain now >= deadline fails across the wrap, for example now = 5 after the counter wraps and deadline = 0xFFFFFFF0. Time O(1). Common mistake: comparing the raw values and getting a timeout that never fires or fires too early after a wrap.

    c
    #include <stdio.h>
    #include <stdint.h>
    int expired(uint32_t now, uint32_t deadline) {
        return (int32_t)(now - deadline) >= 0;
    }
    int main(void) {
        printf("%d %d %d\n", expired(5, 0xFFFFFFF0u), expired(0xFFFFFFE0u, 0xFFFFFFF0u), expired(100, 100));
        /* 1 0 1 */
        return 0;
    }
  5. 5

    Simulate round-robin scheduling and report the completion order.

    medium

    Keep a queue of (task, remaining time). Pop the head, run it for the minimum of the quantum and its remaining time, advance the clock, and push it back if unfinished. For burst times A=5, B=3, C=1 with quantum 2, the order of completion is C, B, A with finish times 5, 8 and 9. Time O(total burst / quantum), space O(n). Common mistake: forgetting to add the actual run time, which is smaller than the quantum for the last slice.

    python
    from collections import deque
    
    def round_robin(tasks, q):
        dq = deque(tasks)               # (name, remaining)
        t, done = 0, []
        while dq:
            name, rem = dq.popleft()
            run = min(q, rem)
            t += run
            if rem > run:
                dq.append((name, rem - run))
            else:
                done.append((name, t))
        return done
    
    print(round_robin([("A", 5), ("B", 3), ("C", 1)], 2))  # [('C', 5), ('B', 8), ('A', 9)]
  6. 6

    Rate-monotonic schedulability: apply the utilisation bound.

    medium

    Compute U as the sum of C/T and compare with n (2^(1/n) - 1). For tasks (1, 4), (1, 5), (2, 10), U is 0.65 and the bound for three tasks is about 0.78, so the test passes. The test is sufficient, not necessary; a failing set needs response-time analysis. Time O(n). Common mistake: concluding a set is unschedulable just because U exceeds the bound.

    python
    def rm_ok(tasks):
        n = len(tasks)
        u = sum(c / t for c, t in tasks)
        bound = n * (2 ** (1 / n) - 1)
        return round(u, 3), round(bound, 3), u <= bound
    
    print(rm_ok([(1, 4), (1, 5), (2, 10)]))  # (0.65, 0.78, True)
  7. 7

    Predict the size of a struct with and without the packed attribute.

    easy

    Without packing, a char followed by an int is padded so the int is 4-byte aligned, so the size is 8. With GCC's packed attribute, padding is removed and the size is 5, but accessing the int member may be a misaligned access, which is slower or illegal on some cores. Output: 8 5. Common mistake: using packed structs for convenience and then taking pointers to their members.

    c
    #include <stdio.h>
    struct A { char c; int i; };
    struct __attribute__((packed)) B { char c; int i; };
    int main(void) {
        printf("%zu %zu\n", sizeof(struct A), sizeof(struct B));
        return 0;
    }
  8. 8

    Predict the output of a switch statement with missing breaks.

    medium

    Execution enters at the matching case and falls through every following statement until a break or the end of the switch. With x = 2, case 2 prints B, then case 3 prints C and breaks, so the output is BC. With x = 5, only the default runs and prints D. Output: BC D. Common mistake: assuming each case ends on its own; compilers warn about unintended fall-through.

    c
    #include <stdio.h>
    void f(int x) {
        switch (x) {
            case 1: printf("A");
            case 2: printf("B");
            case 3: printf("C"); break;
            default: printf("D");
        }
    }
    int main(void) { f(2); printf(" "); f(5); printf("\n"); return 0; }
  9. 9

    Dispatch through a table of function pointers and predict the output.

    medium

    The array holds three functions, and the loop calls each with the running value: add 3 gives 3, double gives 6, subtract 1 gives 5. The table-driven approach is common for state machines and command handlers because adding a state is adding a row. Output: 3 6 5. Common mistake: indexing past the end of the table, so check the index against the table size first.

    c
    #include <stdio.h>
    static int add3(int x) { return x + 3; }
    static int dbl(int x)  { return x * 2; }
    static int dec(int x)  { return x - 1; }
    int main(void) {
        int (*t[])(int) = {add3, dbl, dec};
        int v = 0;
        for (size_t i = 0; i < sizeof t / sizeof t[0]; i++) {
            v = t[i](v);
            printf("%d ", v);
        }
        puts("");  /* 3 6 5 */
        return 0;
    }
  10. 10

    Reverse a string in place.

    easy

    Swap the first and last characters and move both indices inward until they meet. For "firmware" the result is "erawmrif". Time O(n), space O(1). The string must be a modifiable array, not a literal pointer, since writing to a string literal is undefined. Common mistake: calling strlen in the loop condition on every iteration, which makes it quadratic.

    c
    #include <stdio.h>
    #include <string.h>
    void reverse(char *s) {
        size_t i = 0, j = strlen(s);
        while (j > i + 1) {
            j--;
            char t = s[i]; s[i] = s[j]; s[j] = t;
            i++;
        }
    }
    int main(void) {
        char s[] = "firmware";
        reverse(s);
        puts(s);  /* erawmrif */
        return 0;
    }
  11. 11

    Convert a byte array to an uppercase hexadecimal string without printf.

    medium

    Look up each nibble in a 16-character table, high nibble first, and finish with a terminating zero. For bytes 0xDE, 0xAD, 0x01 the output is DEAD01. Time O(n), space O(2n + 1). Common mistake: forgetting the terminator, or writing the low nibble first.

    c
    #include <stdio.h>
    #include <stdint.h>
    #include <stddef.h>
    void to_hex(const uint8_t *b, size_t n, char *out) {
        static const char d[] = "0123456789ABCDEF";
        for (size_t i = 0; i < n; i++) {
            out[2 * i]     = d[b[i] >> 4];
            out[2 * i + 1] = d[b[i] & 0x0F];
        }
        out[2 * n] = '\0';
    }
    int main(void) {
        const uint8_t b[] = {0xDE, 0xAD, 0x01};
        char s[7];
        to_hex(b, 3, s);
        puts(s);  /* DEAD01 */
        return 0;
    }
  12. 12

    Find the maximum sum of a contiguous subarray (for example, the strongest burst in a sensor trace).

    hard

    Kadane's algorithm keeps the best sum ending at the current element: cur = max(x, cur + x), and tracks the best seen. For [-2, 1, -3, 4, -1, 2, 1, -5, 4] the answer is 6 from [4, -1, 2, 1]. Time O(n), space O(1). Common mistake: initialising the best to 0, which is wrong when all values are negative; initialise it to the first element.

    python
    def max_subarray(a):
        best = cur = a[0]
        for x in a[1:]:
            cur = max(x, cur + x)
            best = max(best, cur)
        return best
    
    print(max_subarray([-2, 1, -3, 4, -1, 2, 1, -5, 4]), max_subarray([-3, -1, -2]))  # 6 -1

Frequently asked questions

What coding problems do embedded roles get?

Commonly reported are bit manipulation, buffers, parsing, state machines, scheduling arithmetic and C output prediction. Standard algorithms appear too, at easy to medium level.

Should I solve these in C?

Yes where you can, since embedded roles expect C. Python is fine for the scheduling and algorithm problems if the test allows it.

Are these real NXP problems?

No. They are practice problems in the style of topics such tests are commonly reported to cover. The company does not publish its papers.

How do I practise timing and scheduling questions?

Do the arithmetic by hand with small numbers, then confirm with a short simulation, as the Python solutions here do.

Related guides

More in Company Interview Questions

See all in this section