AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: Vikram — December 18, 2007
    -11 votes
      + -

    Actually the best thing is to sort the array in ascending order (u could use merge / heap sort). Now this takes care of umpteen number of colours also. So if your array has 4 different colours

    RBBGYRRBBGGYYRR
    after sorting would look like
    BBBBGGGRRRRRYYY

    this should solve the issue

  2. Submitted By: keicho — January 31, 2008
    +0 votes
      + -

    /*my answer is O(n), where n is the size of the guess*/

    string (string& sol, string& guess) {
    int color=0, location=0;
    int used[4];
    used[0] = used[1] = used[2] = used[3] = 0;
    for (int i = 0; i

  3. Submitted By: keicho — January 31, 2008
    not yet rated
      + -

    aah well i was using a hashmap that stores the number of colors used. each time you check a color for location, if fails, then you check if there are still remaining. If there is then decrease the hashmap[color] by 1;

  4. Submitted By: Mo — February 5, 2008
    +2 votes
      + -

    Here\’s a hint:
    Just create two hashtables with color->count maps.
    iterate over the guess, and increment colorcount;
    Do a end to end scan to figure out what locations match.
    O(n).

  5. Submitted By: ankit — March 9, 2008
    -2 votes
      + -

    let us consider 4 location to fill [1],[2],[3],[4].
    and four boxes containing balls of color blue[b],yellow[y],red[r],&green[g].

    now [1] location can be filled by any type of balls.so it can be filled by any of 4 color balls.

    now [2] location can be filled by any type of balls.so it can be filled by any of 4 color balls.

    now [3] location can be filled by any type of balls.so it can be filled by any of 4 color balls.

    now [4] location can be filled by any type of balls.so it can be filled by any of 4 color balls.

    now the total of arrangements is equal to =4*4*4*4
    =256
    but at one time only one arrangement is possible with location.
    so a chance that one will guess a right solution is =1\256.

    a chance that one will guess wrong solution is 255\256.

    hence our response to the user for a solution is 1\256
    and for wrong guess is 255/256.

  6. Submitted By: MK — March 17, 2008
    not yet rated
      + -

    We can use 2 Lists one to hold elements of solution and one to hold elements of guess. We need 2 counters locCnt which counts number of Locations and clrCnt which counts number of colors. Now take each color in guess list and find the index of this color in Solution list if index of this color in solution list matches index of color in guess list matching location is found, increment location count and replace element at this location in solution list with a dummy value so that it is not used again, if color element is not found in solution at all continue with next element in guess list, if color element is found in solution list at an index different than that of the guess list check if guess list has same color at the index returned from solution list if so just continue as this will be accounted for later, if not increment the color count by one and replace the element in solution list with a dummy value so that it is not used again..

  7. Submitted By: Chetna — March 19, 2008
    +0 votes
      + -

    Lets say solution is ‘RGTS’
    and the guess is ‘PSTO’

    Put these two in two arrays
    arr_sol = {R ,G ,T , S}
    arr_guess = { P, S , T ,O}

    now take two counter
    location_count =0
    colour_count = 0

    logic for the same is :
    (This logic is applicable for n colours of solution)

    for (i =1 to length.arr_sol) {
    for (j=1 to lenght.arr_guess){
    if(arr_guess[j] == arr_guess[i]) {
    if(j==i) {
    location_count++;
    }else{
    colour_count++;
    }
    }//end of innner for
    }//end of outer for

    if (location_count == lenght.arr_guess && colour_count == 0){
    print”This is the right solution ”
    }else {
    print ” The solution is incorrect”
    }
    print “The number of colur and location as :
    colour_count and location_count “

  8. Submitted By: rakesh — April 9, 2008
    +1 votes
      + -

    We have to consider one more scenario in our answer:
    correction solution: BYRG
    guess:YYRG
    Here, the correct response would be 1 location.
    But using Chetna’s solution above, we will get 1 location, 1 color.
    so we have to have n*n(where n are number of spots) comparisons to check this case out:
    for(i=1; i

  9. Submitted By: Pedja — April 16, 2008
    not yet rated
      + -

    int pos = 0;
    int col = 0;
    for (int i = 0; i -1)
    {
    col++;
    }
    }

  10. Submitted By: J1gs4w — June 2, 2008
    +1 votes
      + -

    Sorry, the answer to the example above is 3 locations, 0 color

  11. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.