Yahoo Interview Question for Software Engineer / Developers






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

hash

- Anonymous September 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Why not a BST?

- Murali Mohan September 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

because suppose there are many occurrence of an number in BST whenever you find first occurance you just terminate search operation right? so we cant find all occurance of number

- ramu September 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

dude, we are not storing elements for each occurrence.. instead we store count so an element at any time is stored only once.. so yes bst is good too.. but searching in bst = O(log n) but for hash its O(1)..

- son_of_a_thread August 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

the only catch here is the space storage.. hashmap's load factor is 0.75 so if we have only 14 elements, hashmap will allocate a space of 22 wasting 8 storage units of space..

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

It would be better if we used Counting sort to sort the data and also we keep the record of occurrence of element

- afs.abhishek October 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can create a structure like this
struct node{
int n;
int count;
struct node *left;
struct node *right;
};
then we will create a bst
whenever the element will be encountered for the first time then it will be added to the best else the count will be incremented for that particular element

- dheeraj October 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/// Using BST Method

struct Node
{
    int val;
    int cnt;
    Node * left;
    Node * right;
    Node(int v = 0, int n = 1) : val(v), cnt(n), left(NULL), right(NULL)
    {
    }
};
Node * insert_bst(Node * root, int v)
{
    if(NULL == root) {
        Node * r = new Node(v);
        return r;
    }
    Node * cur = root;
    while(cur) {
        if(cur->val == v) {
            cur->cnt ++;
            break;
        }
        else if(cur->val < v) {
            if(NULL == cur->right) {
                cur->right = new Node(v);
                break;
            }
            cur = cur->right;
        }
        else {
            if(NULL == cur->left) {
                cur->left = new Node(v);
                break;
            }
            cur = cur->left;
        }
    }
    return root;
}

- zombie June 18, 2013 | 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