Interview Question






Comment hidden because of low score. Click to expand.
0
of 0 vote

use hash table

- xmagics September 13, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use hash table....
if the is no collision no repeated char ...

- DinakaranGCT September 13, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i have a doubt..
using hashtable, how do we get to know the first element of the array to be non repeating?
eg, array- e e a i r a
in hash table we have it as-
a-a
e-e
i
r
ans shud be 'e'. but we have 'a' in the hash table..

- ssn September 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

first 'non-repeating' element in the array.

how is 'e' an answer ? it should be 'i'.

- Anonymous June 25, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i have a doubt..
using hashtable, how do we get to know the first element of the array to be non repeating?
eg, array- e e a i r a
in hash table we have it as-
a-a
e-e
i
r
ans shud be 'e'. but we have 'a' in the hash table..

- ssn September 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

linked list seems to be one option....but the complexity is bad...

- Anonymous September 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorting is one option too :)

- Killer Drama September 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One more solution ...
Assume all letters ... use hash of 26 locations initial all locations as zero
1. Scan the array,
if(hashArray[arr[i]-65]==0)
hashArray[arr[i]-65] = i;
else
hashArray[arr[i]-65] = -1 ;
2. Scan the hasharray and find the min amongst elements excluding 0 and -1. say min
3. print arr[min]

Basically this logic can be expanded furthur to other range of characters just that the hash array to search will be bigger

- Anonymous September 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One more solution ...
Assume all letters ... use hash of 26 locations initial all locations as zero
1. Scan the array,
if(hashArray[arr[i]-65]==0)
hashArray[arr[i]-65] = i;
else
hashArray[arr[i]-65] = -1 ;
2. Scan the hasharray and find the min amongst elements excluding 0 and -1. say min
3. print arr[min]

Basically this logic can be expanded furthur to other range of characters just that the hash array to search will be bigger

- Killer Drama September 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

best solution

- bish November 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

(1) use an array of 256 length and initialized to 0
(2) increment respective position in the array related to that char
(3) iterate thro string and find the first 0-values position in the array, the char correspoding to that location is the required answer

- mail2vcp@gmail.com September 30, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use a bitHash . use a bool vector . initialise it with zero . for every char found we toggle that bit . If in course of iteration we are trying to switch a bit off , we have found the char .
t.c -O(n)
s.c- very less : 256 bits or 8 int instead of 256 int arr.

- Anonymous September 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

u idiot.. u have to find the first no-repeated element not the first repeated element!!

- Anonymous November 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here's Python:

def first_non_rep(array):
    INF = len(array)
    if not INF:
        return None
    tbl = {}
    for i, c in enumerate(array):
        tbl[c] = INF if c in tbl else i
    min_c = min(tbl[c] for c in tbl)
    if min_c == INF:
        return None
    return array[min_c]

print(first_non_rep('abracadabra'))

- Bullocks December 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 0 vote

xor

- surana September 15, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

wont work

- Anonymous September 17, 2008 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More