Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:46:09+00:00 2026-06-17T17:46:09+00:00

I read of a job interview question to write some code for the following:

  • 0

I read of a job interview question to write some code for the following:

Write an efficient function to find the first nonrepeated character in
a string. For instance, the first nonrepeated character in “total” is
‘o’ and the first nonrepeated character in “teeter” is ‘r’. Discuss
the efficiency of your algorithm.

I came up with this solution in Python; but, I’m sure that there are way more beautiful ways of doing it.

word="googlethis"
dici={}

#build up dici with counts of characters
for a in word:
    try:
        if dici[a]:
            dici[a]+=1
    except:
        dici[a]=1

# build up dict singles for characters that just count 1 

singles={}
for i in dici:
    if dici[i]==1:
        singles[i]=word.index(i)

#get the minimum value

mini=min(singles.values())

#find out the character again iterating...

for zu,ui in singles.items():
    if ui==mini:
        print zu 

Is there a more concise and efficient answer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:46:10+00:00Added an answer on June 17, 2026 at 5:46 pm
    In [1033]: def firstNonRep(word):
       ......:     c = collections.Counter(word)
       ......:     for char in word:
       ......:         if c[char] == 1:
       ......:             return char
       ......:         
    
    In [1034]: word="googlethis"
    
    In [1035]: firstNonRep(word)
    Out[1035]: 'l'
    

    EDIT: If you want to implement the same thing without using helpers like Counter:

    def firstNonRep(word):
        count = {}
        for c in word:
            if c not in count:
                count[c] = 0
            count[c] += 1
        for c in word:
            if count[c] == 1:
                return c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently read a sample job interview question: Write a function to convert an
I had an interesting job interview experience a while back. The question started really
I have developed a code that runs a map reduce job to read files
I'm getting the following error when trying to read a SQL Job. The SELECT
At a recent job interview, I was asked to implement my own string copy
I have following code. <entry> <job:location> <job:id>24</job:id> <job:region>6</job:region> </job:location> </entry> I've problem with namespaces.
This was inspired by a question at a job interview: how do you efficiently
I've read about how a hard job in programming is writing code at the
I have a Read generic function that does its job very well. It reads
I just read this requirement on a job listing: Aware of the pitfalls of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.