Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ1058
Page ↗
Q1058FWNVIDIAASIC interview problem

Bounded byte-string palindrome check

TechniquesFirmware & ValidationFirmware / Validationbounded byte-string palindrome check
DifficultyEasy
TopicFirmware & Validation
LanguageC
Requirements4 checkpoints
01

Problem

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.

Starting declarationC
bool is_palindrome(const uint8_t *p, size_t n);

Example input and output

Use this case to check your interpretation
Input
p=NULL and n=0.
Output
Return true.
Explanation

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

02

Requirements (4)

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