Skip to content

Resource · Guide or article

Hamming Distance

A brief definition of Hamming distance: the count of positions where two equal-length strings differ, framed as the minimum number of substitutions between them.

Reviewed

Open the original: Hamming Distance (opens the original site in a new tab)

Practice this topicOpens the practice interviewer in Technical / coding mode; choose a question there.

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. In other words, it measures the minimum number of substitutions required to change one string into the other, or the minimum number of errors that could have transformed one string into the other. In a more general context, the Hamming distance is one of several string metrics for measuring the edit distance between two sequences.

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Reference

What it covers

  • Defines the metric and relates it to edit distance
  • Works four examples covering names, binary strings and digit strings

How to use it

PrepKit study advice, not a claim made by the source.

Compute the four examples by hand, then write a function that rejects strings of unequal length before counting.

Scope and limitations

Definition and examples only, with no algorithm discussion, complexity or exercises. The only reference is Wikipedia.

Access and format

Short README on GitHub, trekhleb/javascript-algorithms (MIT). English, free to read.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/string/hamming-distance/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email