Prepin
Log in

Create a program that identifies characters in a string that do not repeat.

Approach / Explanation

The task at hand is to develop a program that can detect characters in a string that do not repeat. A "non-repeatable character" refers to a character that occurs just once within the string. For instance, with the input string "interviewer" , the non-repeatable characters are "i", "n", "t", "w", "r" since they each appear solely once in the string. Consider the following important points: You need to traverse the entire string to examine each character. It's essential to count how many times each character occurs. After completing your iterations, you will identify the characters that appear only one time.

Suggested Answer

A potential method to tackle this issue is by utilizing Python along with the built-in collections Counter feature. The implementation of this method is outlined in the following code: from collections import Counter def non_repeating ( string ) : count = Counter ( string ) non_repeater = [ item for item in count . elements ( ) if count [ item ] == 1 ] return non_repeater print ( non_repeating ( 'interviewer' ) ) In this script, we begin by employing the Counter() function to determine the frequency of each character within the string. We then loop through these frequencies, adding characters to the non_repeater list only when their frequency is equal to 1, indicating that they are non-repeating characters.

Alternative Answer

Another approach to tackle this problem is by utilizing two for loops. Let's take a look at the code in Python: def non_repeating ( string ) : non_repeater = [ ] for i in range ( len ( string ) ) : flag = False for j in range ( len ( string ) ) : if string [ i ] == string [ j ] and i != j : flag = True if flag == False : non_repeater . append ( string [ i ] ) return non_repeater print ( non_repeating ( 'interviewer' ) ) This code defines a function called non_repeating() , which starts with an empty list named non_repeater . It then utilizes two for loops to compare each character in the string with every other character. If a duplicate character is found, the flag variable is set to True . If no duplicates are detected (meaning flag remains False ), the character is appended to the non_repeater list. This process is carried out for each character in the string.

Question Details

Difficulty & Category

Medium

Companies

Visa

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.