Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/Clean palindrome check

Q032·Free·SystemVerilog

Clean palindrome check

Difficulty
Easy
Topic
Strings
Language
SV
Interview prompt

Question

Return 1 when an ASCII string is a palindrome after ignoring non-alphanumeric bytes and letter case. ASCII letters and digits participate in the comparison.

Candidate starting point

Implementation scaffold

function automatic bit is_alnum(byte c);
  // TODO: identify ASCII letters and digits.
endfunction

function automatic byte to_lower(byte c);
  // TODO: lowercase ASCII uppercase letters; leave other bytes unchanged.
endfunction

function automatic bit is_palindrome_clean(string s);
  // TODO: compare participating bytes from both ends.
endfunction
Reviewed example

Trace one case

Input
s = "A man, a plan, a canal: Panama!"
Expected output
1 (palindrome)

Removing punctuation and folding case produces "amanaplanacanalpanama", which reads the same in both directions.

What to cover

Requirements

  1. Skip non-alphanumeric bytes from both ends.
  2. Compare letters case-insensitively.
  3. Treat an empty cleaned string as a palindrome.
Exact question handoffPractice Q032

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessEach time you open this Solution, one Practice Credit is used; it is not permanently unlocked. Premium Solution content also uses one credit per opening.
Continue learning

Firmware Guide

Review algorithms, data structures, fixed-memory reasoning, concurrency, and silicon bring-up.

  • Strings
  • String
  • Two pointers
Firmware Guide →
Continue practicing

Related questions

Q1115 · Firmware & ValidationBounded byte-string palindrome checkEasyP→Q251 · Reference ModelsVerify a decimal palindrome checkerMediumP→Q989 · ConstraintsConstrain and cover an ASCII palindrome checkerHardP→Q508 · SystemVerilog ConstraintsRandom palindrome array constraintMediumP→
ASIC.FYI · Learn silicon end to end.info@asic.fyi