Amazon Interview Question for Software Engineer / Developers






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

Hey googler, could you please clarify the question... with Sample input and Sample output

- Crime_Master_GoGo December 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* 26-bit mask  i.e 1-bit for each character from 'a' to 'z' */

void FindRepeartedCharacters(char *S)
{
    if( S == NULL )
        return ;
    else
    {
        int len = strlen(S);
        int i=0;
        int MASK:26 = 0; // bit-filed

        while(i < len -1 )
        {
            if ( alpha(S[i] )
            {
                if( S[i] >= 'A' && S[i]<='Z')
                {
                    S[i] = lower(S[i]);
                }

                if( MASK & (1<< (S[i] - 'a')) )
                {
                    printf("\n %c is repeated", S[i]);
                }
                else
                {
                        MASK | =  1<< (S[i] - 'a') ;
                }
            }
            else
            {
                printf("\n wrong input ");
                exit(0);
            }
            i++;
        }

    }
}

- siva.sai.2020 December 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question says you can change the mask...

- doubt February 01, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* 52-bit mask  i.e 2-bit for each character from 'a' to 'z' */
/* 0,1st bits for 'a'. 2,3rd bits for 'b' ... */
/* if two bits are 1 for a character , then character is repeated */

void FindRepeartedCharacters(char *S)
{
    if( S == NULL )
        return ;
    else
    {
        int len = strlen(S);
        int i=0;
        int MASK:52 = 0; // bit-filed

        while(i < len -1 )
        {
            if ( alpha(S[i] )
            {
                if( S[i] >= 'A' && S[i]<='Z')
                {
                    S[i] = lower(S[i]);
                }

                if( MASK & (1<< (S[i] - 'a')*2) )
                {
                     MASK | =  1<< ((S[i] - 'a')*2 + 1 ) ;
                }
                else
                {
                        MASK | =  1<< (S[i] - 'a')*2 ;
                }
            }
            else
            {
                printf("\n wrong input ");
                exit(0);
            }
            i++;
        }// end of while
        i=0;
        while(i<26)
        {
            if( (MASK & 1<<2*i) && (MASK & 1<<(2*i + 1) ) )
            {
                printf("\n %c is repeated \n", i + 'a' );
            }
        }


    }
}

If you find any bug in my code , please let me know

- siva.sai.2020 December 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If possible please give logic and then psuedo-code.

- Anonymous January 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

guys..question it nt put in a right way..the question is how to find the repeated elements in a string?

Suppose for exp: in the string "rajinikanth"..char 'i','a','n'... is repeated...using the mask as given above it can done..

- Newbie January 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can someone pls clarify what the masking operation exactly does? How does it solve the problem of finding repeated characters???

- div January 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

find a repeated string is ok using bit mask but for a set of strings without changing the bit mask ?

- nmc February 26, 2011 | Flag Reply


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