Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Bounded byte-string palindrome check

Hardware interview practice

Bounded byte-string palindrome check

EasyFirmware & ValidationC

A firmware diagnostic receives a byte buffer and length; the bytes are not NUL-terminated. Write the C function that reports whether the buffer reads the same forward and backward.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

bool is_palindrome(const uint8_t *p, size_t n);
Reviewed example

Work through one case

Input
p=NULL and n=0.
Expected output
Return true.

The empty byte sequence is a palindrome, and the function handles that case before dereferencing p or computing n-1.

What to cover

Requirements

  1. Return true for lengths zero or one; p may be NULL only when n is zero.
  2. For n greater than zero, return false if p is NULL.
  3. Compare byte values exactly, including zero bytes, and do not modify the buffer.
  4. Run in O(n) time with O(1) extra storage and avoid index underflow for n=0.
Continue practicing

Related questions

Firmware & ValidationBounded MMIO command driver→Firmware & ValidationLocate the payload in an Ethernet frame→Firmware & ValidationCount errors in a build report→
asic.fyi · Learn silicon end to end.info@asic.fyi