Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Hex String Check

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Hex String Check. Start with the requirements on the right.

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.

Problem

Zebra DataWedge integrations may receive diagnostic payloads represented as hexadecimal bytes. Implement a validator that determines whether an input string is a valid hexadecimal byte string.

A valid string contains one or more hexadecimal digits, 0-9, a-f, or A-F. It may optionally begin with 0x or 0X. After removing that prefix, the string must contain an even number of hexadecimal digits because each byte requires two digits. Do not accept whitespace, signs, separators, an empty string, or a prefix without digits.

Formal Specification

Given a string s, return True if it satisfies the rules above; otherwise return False. The input is a Python str, and the output is a Boolean.

Constraints

  • 0 <= len(s) <= 10^5
  • The input is a Python string containing printable ASCII characters
  • The payload must contain an even number of hexadecimal digits
  • The entire value must not be converted to an integer

Function Signature

def is_hex_payload(s):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output