No Duplicate Letters Java Coding Challenge | How'd You Code That?

Опубликовано: 10 Август 2026
на канале: Ed Clark
49
6

No Duplicate Letters

Other videos like this:
Duplicate Count:    • Duplicate Count in Linear Time Java Coding...  

Today, we’re solving the No Duplicate Letters challenge, where, Given a common phrase, our method should return false if any individual word in the phrase contains duplicate letters, and true otherwise.
Since there are multiple ways to skin a cat, we’re going to talk through two common solutions for this type of problem. At the end of video, if you know which solution is the most efficient, please, comment below.
If you have questions about either solution, ask it the comments below.

The main method of our solution utilizes a StringTokenizer, which splits our phrase into groups of words.
First, we instantiate a new StringTokenizer, having the value of the phrase, delimited by a space.
Next, while our tokenizer has tokens, we initialize a String, aptly named, word, with the value of the token.
If the word doesn’t contain all unique letters, determined by the call to the uniqueCharacters method, false is returned to caller, otherwise, the loop continues, until all words have been evaluated.
If the loop finishes evaluating all words successfully, none of the words contained duplicate letters, and true is returned to the caller.

There are two possible implementations of the uniqueCharacters method.
The first, uses two nested loops to evaluate each character in a string and returns false when a duplicate is found. If all characters are evaluated and a duplicate is not found, true is returned.

The second implementation uses a HashSet.
Each character in the string is inserted into the HashSet. If the character is found to already exist in the HashSet, false is returned to the caller. If all characters are evaluated and a duplicate is not found, true is returned.

Which implementation of the uniqueCharacters method is most efficient? Comment below.

Song: Mystery - Ikson (Vlog No Copyright Music)
Music promoted by Vlog No Copyright Music.
  / ikson