## v.krishna1708

BAN USERUsing Min Heap won't work here because the word which is popping off from min heap due to less count at current situation... may be this word can occur more times than the incoming word into heap...

so min heap wont work for this problem.

int numOfOneBits(int number)

{

int count = 0, leftShift = 0;

while(number >= (1 << leftShift))

{

if(number & (1 << leftShift))

count++;

leftShift++;

}

return count;

}

switch is a conditional statement not condition operator

- v.krishna1708 April 23, 2014Time Complexity : O(n)

Space Complexity : Input Range (works for only +ve numbers)

Data Structure Used : Hash table[1..100]

Algorithm :

1. Initialize Hash table[1...100] with 0.

2. Now Read values one by one in a variable index

// read----> index

3. Now increment the value in hash table at location of index

// hash_table[index]++;

4. If input is NOT over then go to step 2

else go to next step.

5. Now traverse the whole hash_table and print 'index' simultaneously wherever we get the value greater than 0.

6. STOP

//it will also keep the duplicates

/// little bit edited and more explained soln of above algo

time complexity : O(nlogn)

typedef struct node

{

int start;

int finish;

}node;

algorithm :

{

1. Use the Priority_Queue <node> data structure

by setting the priority of increasing finish time...

// means the one having less end_time will have greater priority;

2. Then pop first node from priority_queue;

and set last_finish=node.finish;

Then pop nodes from priority_queue until Priority_queue is empty...

if(node.start>last_finish)

{ last_finish=node.finish;

and Doctor is NOT_BUSY in current node appointment

// so appointment is possible

}

else

{

Doctor is BUSY in current node appointment;

// so appointment is not possible in this

}

}// end

----question based on activity selection

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

- v.krishna1708 February 02, 2018