[algogeeks] Re: google question

2012-02-26 Thread Dumanshu
You are assuming is to be a binary tree, its not. Some nodes will share a common pour. On Feb 25, 9:24 pm, atul anand atul.87fri...@gmail.com wrote: i guess this would work... n=number of nodes h=height; pour=quantity poured; capacity = capacity of each cup n=pow(2,h+1) -1;

[algogeeks] Re: Google Question--Suggest Algo

2011-11-28 Thread Dumanshu
Hi I may not have understood your solution properly. But i think that your solution is an implementation of brute force where you are dealing with all cases valid in the range n/2k and 3n/2k without any optimization with regard to DP. Am i right? On Nov 28, 2:17 am, sourabh

[algogeeks] Re: Facebook Campus Test Question

2011-11-04 Thread Dumanshu
plz post a samle input output.. On Nov 4, 10:24 am, sunny agrawal sunny816.i...@gmail.com wrote: What can be a better solution than a Brute Force O(N^2* No of iteration) -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee  fb1_input.txt 1KViewDownload  

[algogeeks] Re: Facebook Campus Test Question

2011-11-04 Thread Dumanshu
is ur brute force O(1) for space? On Nov 4, 10:24 am, sunny agrawal sunny816.i...@gmail.com wrote: What can be a better solution than a Brute Force O(N^2* No of iteration) -- Sunny Aggrawal B.Tech. V year,CSI Indian Institute Of Technology,Roorkee  fb1_input.txt 1KViewDownload  

[algogeeks] Re: Intersection of arrays

2011-10-28 Thread Dumanshu
I think Dan's solution is the best one here. TC O(n log n) and SC O(1) where n is the maximum no. of elements in any array Instead of starting with K given arrays, just take the first 2. Sort both of them - time is nlogn Now run two pointers on each array to save the common elements as they are

[algogeeks] Re: Amazon OS question

2011-10-28 Thread Dumanshu
How are we going to write a program which if fed the data gives the answer? Any ideas for the algorithm? My approach: We have a graph here. We have vertices with indegree 0 and outdegree 1. - call it set A (start points) (m vertices) We have vertices with indegree 1 and outdegree 0. - call it

[algogeeks] Re: google os ques on pipelining

2011-09-26 Thread Dumanshu
@bharat: for the second part where u multiplied (160+5) with 999, it should be 160*999 because it is max of (150,120,160,140,5). Correct me if i am wrong. On Sep 26, 4:02 pm, bharatkumar bagana bagana.bharatku...@gmail.com wrote: for the first instruction : 150+5+120+5+160+5+140=585 ns for the

[algogeeks] Re: convert a word into a palindrome with minimum addition of letters to it

2011-09-07 Thread Dumanshu
@Victor: Instead of 0 and 1, shouldn't it be like DP[i-1][j-1] + 0 and DP[i-1] [j-1] + 1 On Sep 7, 1:10 am, Victor Manuel Grijalva Altamirano kavic1.mar...@gmail.com wrote: Try with DP, a little modicated of Edit Distance algorithm State i=the begin of the word , j=the end of the word

[algogeeks] Re: convert a string into another in minimum number of steps

2011-08-31 Thread Dumanshu
how to check if intermediate words are dictionary words or not?? Also what would be the approach for that? On Aug 31, 3:10 am, icy` vipe...@gmail.com wrote: Yea, I hope the intermediate words are dictionary words; it's  more fun that way.   I played such a game before, where you and a friend

[algogeeks] Re: How to save a binary search tree space efficiently

2011-08-30 Thread Dumanshu
Level Order traversal if you are ok with the Nulls being stored. Otherwise its pre order traversal. On Aug 30, 12:34 pm, Vidit Sinha vidit.it...@gmail.com wrote: whats the final answer guys? Level order traversal?? On Tue, Aug 30, 2011 at 12:56 AM, Don dondod...@gmail.com wrote: I'm

[algogeeks] Re: stack using bst

2011-08-26 Thread Dumanshu
So, in short you are using a BST and a FIFO linked list. Whereas, a Stack is actually a LIFO linked list. Am i right? On Aug 25, 11:37 pm, Don dondod...@gmail.com wrote: You will have to keep two pointers, one to the root of the tree and one to the head of the FIFO linked list. To push, insert

[algogeeks] Re: print all paths which sum up to a value.

2011-08-24 Thread Dumanshu
Any help regarding the preprocessing required for O(1) operation for LCA??? I read the wiki's article involving eulers traversal.. but its nt clear. On Aug 24, 1:12 am, DK divyekap...@gmail.com wrote: Hmm.. Interesting question. *Here's a solution:* There are n elements in the tree and

[algogeeks] Re: Longest palindrome

2011-08-22 Thread Dumanshu
So, suggest some approach plz for this ques. On Aug 22, 12:59 am, Dave dave_and_da...@juno.com wrote: @Sanjay: Will method 1 really work? What would it return on the string abraxyzarba? The longest common substring between this string and its reverse is abra, but how does that relate to the

[algogeeks] Re: another q on ds!

2011-08-21 Thread Dumanshu
first option is correct. Because we are not allowed to use any extra space. On Aug 21, 6:36 pm, priya ramesh love.for.programm...@gmail.com wrote: A Most efficient data structure is designed to optimize the following operations. Pop, Push, Min. The best possible time-complexities with no extra

[algogeeks] Re: amazon q

2011-08-21 Thread Dumanshu
We can't use a heap. Balanced BST is correct because Deletion of the smallest element Insertion of an element if it is not already present in the set - for this we need to search for the element and searching in heap is O(n). On Aug 21, 6:16 pm, priya ramesh love.for.programm...@gmail.com wrote:

[algogeeks] Re: Algorithm complexity

2011-08-03 Thread Dumanshu
Check interpolation which is a substitute for binary search for a uniformly sorted array. It has complexity of this order. On Aug 3, 7:31 pm, Ajai Sathyan ajaisath...@gmail.com wrote:  Can you suggest a sample program which has complexity O(log log n)? Regards Ajai Sathyan -- You received

[algogeeks] Subsequence with Sum S

2011-07-30 Thread Dumanshu
Given an array of length n of integer numbers. Output 1 or 0 depending on whether or not there exists a sub sequence in the array with sum S. Suggest a fastest algorithm plz. e.g. say given an array with numbers as 10 20 30 40 50 60 70 Sum = 110 Output is 1 because 20+30+50 is 110. -- You

[algogeeks] Re: interview ques

2011-07-27 Thread Dumanshu
Use multilevel indexing On Jul 27, 11:07 pm, himanshu kansal himanshukansal...@gmail.com wrote: if u hv say 20 million records and u have to create a b+ tree then you might be storing 20 million pointers at the leaf levelhow can u optimize this(using b+ tree only)??? -- You received

[algogeeks] Re: MS

2011-07-20 Thread Dumanshu
check the above solution.. urs is O(logn) mine is O(log k). On Jul 19, 11:35 pm, sagar pareek sagarpar...@gmail.com wrote: well i dont think so...any better solution will be there compare mine one On Wed, Jul 20, 2011 at 12:00 AM, Dumanshu duman...@gmail.com wrote: heres the code

[algogeeks] Whats the complexity?

2011-07-20 Thread Dumanshu
Given an infinite length list. u got to find index of an element k. use this approach- initially, take length as 2^x where x increases from 1 to ... while (still not found) { now if arr[2^x-1] k, increment x else binarysearch on length 2^(x-1) to 2^(x) } Please help me to find the

[algogeeks] Axis­ Aligned Rectangles

2011-07-20 Thread Dumanshu
Describe
 an
 algorithm 
that
 takes an 
unsorted 
array 
of 
axis‐ aligned 
rectangles 
and returns 
any 
pair 
of 
rectangles 
that overlaps, 
if 
there 
is such 
a 
pair. 

Axis‐aligned means 
that all 
the
 rectangle 
sides 
are 
either 
parallel
 or 
perpendicular to 
the 
x 
and y‐axis.

You

[algogeeks] Re: Whats the complexity?

2011-07-20 Thread Dumanshu
that is why m confused. how would u rate this algo? in what order? On Jul 20, 10:44 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote: when n is not defined , you want complexity in terms of ? On Wed, Jul 20, 2011 at 3:16 PM, Dumanshu duman...@gmail.com wrote: Given an infinite length

[algogeeks] Re: Whats the complexity?

2011-07-20 Thread Dumanshu
it should involve the exponential increment! somebody plz help On Jul 20, 10:56 pm, Ankur Khurana ankur.kkhur...@gmail.com wrote: in my opinion , it is log(indexof(k)) On Wed, Jul 20, 2011 at 11:23 PM, Dumanshu duman...@gmail.com wrote: that is why m confused. how would u rate this algo

[algogeeks] Re: Ever growing sorted linked list

2011-07-19 Thread Dumanshu
..) - suppose you found a certain node at position n whose node-data k , then now u only have to search for k between index n/2 to n (i.e. if you found 16th element k then search for k between 8th and 16ht element).. correct me if any flaws. On Jul 19, 3:38 am, Dumanshu duman...@gmail.com

[algogeeks] Re: Amazon

2011-07-19 Thread Dumanshu
What is the answer to the first one? On Jul 19, 10:07 am, sagar pareek sagarpar...@gmail.com wrote: 1. Let's say S=D=N repeat D=(floor)D/2; S=S-D; till D=0 From the above logic, figure out which algorithm is followed by 'S' 2. How can you divide a triangle, to 5 equal triangles?

[algogeeks] Re: MICROSOFT

2011-07-19 Thread Dumanshu
surender On Tue, Jul 19, 2011 at 4:06 AM, Dumanshu duman...@gmail.com wrote: @Gaurav: The best solution would be to manipulate the given BTree in place and get the BST. We don't need a separate tree but convert the existing one using the same space occupied by nodes of BT already

[algogeeks] Re: MS

2011-07-19 Thread Dumanshu
heres the code http://ideone.com/rX130 On Jul 19, 9:35 pm, swetha rahul swetharahu...@gmail.com wrote: Hi,         Find the kth smallest element in O(logk) given 2 sorted arrays. Merging the arrays is not allowed. I can do it in O(k).. How to do in O(logk).. -- You received this

[algogeeks] Tournament Tree

2011-07-18 Thread Dumanshu
Given billions of unsorted numbers and we need to find first 1 million numbers if all the numbers were sorted in non-descending order. approach is to split up the numbers to multiple machines and sort them. Then make a tournament tree in such a way that each machine feeds the lowest number it has,

[algogeeks] Re: Find the missing number - Again given 4 billion integers

2011-07-18 Thread Dumanshu
Hi sry for not being so clear with the problem statement. The list of numbers may have repetitions. Lots of numbers can be missing from the list, you just need to output any one. Regards Dumanshu BITS-Pilani On Jul 18, 5:28 pm, ankit sambyal ankitsamb...@gmail.com wrote: The question says

[algogeeks] Re: Missing Number in an array

2011-07-18 Thread Dumanshu
Quadratic equation solver: just solve it the way we do on paper, take coefficients as input and apply formula x = (-b+sqrt(b^2 - 4*a*c))/ 2*a... anything wrong with this? And for the given problem, it says atleast once and not exactly once. So, Ankit's solution of bit vector is the best one. On

[algogeeks] Long string and the first non-repeating character

2011-07-18 Thread Dumanshu
You are given a long string and you have to print the first non repeating character. Solve it keeping SC and TC in mind. That is present both solutions, one with high SC and low TC and viceversa. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group.

[algogeeks] Re: MD5

2011-07-18 Thread Dumanshu
here it is -http://rosettacode.org/wiki/MD5 It has the C implementation if u need in C. On Jul 18, 6:09 pm, Anuj kumar anonymize...@gmail.com wrote: some body can give me code of MD5 PLZ its Urgent .. -- You received this message because you are subscribed to the Google Groups

[algogeeks] Ever growing sorted linked list

2011-07-18 Thread Dumanshu
You have a sorted linked list of integers of some length you don't know and it keeps on increasing. You are given a number k. Print the position of the number k. Basically, you have to search for number k in the ever growing sorted list and print its position. Please write the complexity of

[algogeeks] Re: MICROSOFT

2011-07-18 Thread Dumanshu
Lets say DLL is sorted. We have to convert the DLL so basically its the manipulation of pointers. Can we do it recursively? //n is the total number of nodes in the list. // next corresponds to right and prev corresponds to left pointer. Node * BuildBalBST(Node *head, int n) { if(!n) return NULL;

[algogeeks] Re: MICROSOFT

2011-07-18 Thread Dumanshu
1. //BT to BST - function used is to swap values Node* bubbleData(Node *root) { if(!root) return NULL; if(root-right) { if(root-data root-right-data) swap((root-data),(root-right-data)); root-right = bubbleData(root-right); } if(root-left) { if(root-data

[algogeeks] Re: Long string and the first non-repeating character

2011-07-18 Thread Dumanshu
heres my solution with TC O(n) and SC O(26) input string str int arr[26] = {0}; traverse the string, character by character and increment the corresponding counter. i.e. arr[str[i]]++; Now traverse the string again and print out the first character encountered whose arr[str[i]] == 1; On Jul 18,

[algogeeks] Re: MICROSOFT

2011-07-18 Thread Dumanshu
Sry, I made a mistake in my code for problem 1 to convert BT to BST Ignore it ... its wrong any case missing?? 3. Do we have to give an algorithm for garbage collection like Mark sweep algo or Do we have to write a code? if code, plz tell how to write? On Jul 18, 4:59 pm, Balaji S

[algogeeks] Re: MICROSOFT

2011-07-18 Thread Dumanshu
); } } } On Jul 18, 7:24 pm, Dumanshu duman...@gmail.com wrote: 1. //BT to BST - function used is to swap values Node* bubbleData(Node *root) { if(!root) return NULL; if(root-right) {       if(root-data root-right-data)          swap((root-data),(root-right-data));       root-right

[algogeeks] Re: Ever growing sorted linked list

2011-07-18 Thread Dumanshu
. else if (ptr2-datak) set ptr1=ptr2 goto 2 5. else traverse the ptr1 upto ptr2, if found return its position else return fail if anyone has more efficient solution then pls tell  :) On Mon, Jul 18, 2011 at 6:53 PM, Dumanshu duman...@gmail.com wrote: You have a sorted linked list

[algogeeks] Re: MICROSOFT

2011-07-18 Thread Dumanshu
:12 pm, surender sanke surend...@gmail.com wrote: @Dumanshu it also doesn't works, as min node doesn't satisfies bst conditions, u swap it but it again creates inconsistencies with its left subtree. void binarytreetobst(btree *root) {        if(root == NULL)  return;        else if(root

[algogeeks] Re: MICROSOFT

2011-07-18 Thread Dumanshu
@Balaji: for third question, were u asked to write the code? On Jul 18, 10:04 pm, Balaji S balaji.ceg...@gmail.com wrote: wats the mistake.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: is it possible to detect the first repeating number in a 2-D array (n X n) in O(n) time ?

2011-07-18 Thread Dumanshu
You have to use parallel computing to find the first repeating number in O(n) time if theres nothing special about the 2-D array Use n +1 processes, n processes to scan each row and 1 process to scan the rows last and next rows first element to check for repetition. Each process uses hash table to

[algogeeks] Re: MICROSOFT

2011-07-18 Thread Dumanshu
traverse using recursion and instead of printing it just pass to function which is making BST?? and is this right as someone above said first sort it and then make BST... dont we want that root of both Tree to be same or something like that...?? On Tue, Jul 19, 2011 at 2:17 AM, Dumanshu

[algogeeks] Re: Ever growing sorted linked list

2011-07-18 Thread Dumanshu
, Dumanshu duman...@gmail.com wrote: @Swathi: plz give the TC of ur algo (exponential plus log) On Jul 18, 10:14 pm, Swathi chukka.swa...@gmail.com wrote: The solution to this problem will be a combination of exponential increase and the binary search.. start = 0; end = 0; index =0

[algogeeks] Re: Tournament Tree

2011-07-18 Thread Dumanshu
@Ankit: this particular problem can be solved with min heap implementation for tournament tree concept. But i want to code the actual tournament tree, where we can also find out the winner over all and all other contestants that lost to the winner. how to code that? Regards Dumanshu BITS-Pilani

[algogeeks] Median of billion numbers - Map Reduce

2011-07-17 Thread Dumanshu
Given billions of integers in a file. Memory Constraints exist so need to parallelize. One solution can be to split the file over a 100 machines and each machine calculates median of their part using quickselect and sends the result to host machine. Now the host calculates median of these medians

[algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread Dumanshu
plz give some example..sry but what do you mean by child sibling version?? On Jul 16, 3:46 pm, Reynald reynaldsus...@gmail.com wrote: Given a Parent -Child binary tree ,build the child -sibling version of it? Minimize the space requirements wherever possible. -- You received this message

[algogeeks] Re: MS question

2011-07-17 Thread Dumanshu
Well, for the third case, you can elaborate on the implementation. We need to compare the first half with the later half. So, in case of even no. of characters it splits perfectly and in case of odd number of characters, just ignore the middle character. On Jul 17, 8:28 pm, swetha rahul

[algogeeks] Re: Median of billion numbers - Map Reduce

2011-07-17 Thread Dumanshu
+919966006652 On Sun, Jul 17, 2011 at 8:57 PM, Dumanshu duman...@gmail.com wrote: Given billions of integers in a file. Memory Constraints exist so need to parallelize. One solution can be to split the file over a 100 machines and each machine calculates median of their part using

[algogeeks] In-memory dictionary

2011-07-17 Thread Dumanshu
I want to have an in-memory dictionary. One word can have multiple meanings. 1. If you want to go with hash tables then do Suggest some good choices for hash functions. 2. Also, how can you modify this dictionary so that it can be used to solve a crossword puzzle? -- You received this message

[algogeeks] Re: Microsoft Interview Qn

2011-07-17 Thread Dumanshu
@Ashish: if i got ur algo correct, contrary to all the above examples, u r forming a linked list of level order traversal of the tree. m i right? On Jul 17, 8:49 pm, Ashish Goel ashg...@gmail.com wrote: 1. PUSH ROOT IN Q 2. PUSH DUMMY NODE IN Q, DEFINE PREVIOUS NODE AS NULL 3. WHILE Q IS NOT

[algogeeks] Re: In-memory dictionary

2011-07-17 Thread Dumanshu
, Jul 18, 2011 at 1:43 AM, Dumanshu duman...@gmail.com wrote: I want to have an in-memory dictionary. One word can have multiple meanings. 1. If you want to go with hash tables then do Suggest some good choices for hash functions. 2. Also, how can you modify this dictionary so that it can

[algogeeks] Re: MICROSOFT

2011-07-17 Thread Dumanshu
are u sure that this code works??? because last time i checked it didn't. On Jul 18, 1:22 am, hary rathor harry.rat...@gmail.com wrote: int dividend,divisor,remainder; int division(int p,int q){ int quotient=1; /*if divisor and diviend are equal then quotient=1*/ if(p==q){ remainder=0;

[algogeeks] Re: Median of billion numbers - Map Reduce

2011-07-17 Thread Dumanshu
Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sun, Jul 17, 2011 at 8:57 PM, Dumanshu duman...@gmail.com wrote: Given billions of integers in a file. Memory Constraints exist so need to parallelize. One solution can be to split the file over a 100

[algogeeks] Find the missing number - Again given 4 billion integers

2011-07-17 Thread Dumanshu
given 4 billion integers i.e 2^32 integers. find the integer that is not there in the list. Memory constraints - 2^16 bytes can be used at max. Does the presence of -ve numbers affect the solution?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: MICROSOFT

2011-07-17 Thread Dumanshu
@Hary: thanks, ur code works. Could someone tell me the complexity of the above mentioned code??? heres the working version of the same http://ideone.com/fDTfj Its increasing exponentially.. so can we say log_2(n)??? On Jul 18, 1:57 am, Dumanshu duman...@gmail.com wrote: are u sure

[algogeeks] Re: Google interview question

2011-07-16 Thread Dumanshu
how about using voters algorithm? TC O(n) and SC O(1) On Jul 16, 6:28 am, Anand Shastri anand.shastr...@gmail.com wrote: Given a file containing 4,300,000,000  integers, how can you *find **one* that *appears* at *least **twice* -- You received this message because you are subscribed to the

[algogeeks] Re: amazon

2011-07-15 Thread Dumanshu
heres another approach. For given n sets, all permutations have a { in the beginning and } in the end. So, we need to permute the middle string with (n-1) sets. I have generated all the permutations of n sets i.e. say n ==3 then generate all permutations of (n-1==2 sets) {}{} string. Now before

[algogeeks] Re: GOOGLE Q

2011-07-10 Thread Dumanshu
how about this? take pointer p1 set to end of array A and pointer p2 set to end of array B. while(you get n values) { print A(p1),B(p2) now if( A(p1-1)+B(p2)A(p1)+B(p2-1) ) then print A(p1-1),B(p2) followed by print A(p1),B(p2-1) decrement p2 and p1 both } m i missing something? On Jul 9,

[algogeeks] Re: String burn,measure time puzle

2011-07-09 Thread Dumanshu
@oppilas: light the first string at both ends and in the middle. So it will burn completely in 15 min as the fire is advancing in 4 ways irrespective of the burn rate. when the first string is completely burnt, light the second string at both ends to get another 30 min. So, overall 45 min. On

[algogeeks] Re: String burn,measure time puzle

2011-07-09 Thread Dumanshu
an hour to burn, but the burn rate is not constant Can't we have a string which take 45 minutes to burn till half length. 0-L/2. And 15 min from L/2 to L. On Sat, Jul 9, 2011 at 8:57 PM, Dumanshu duman...@gmail.com wrote: @oppilas: light the first string at both ends and in the middle

[algogeeks] Re: String burn,measure time puzle

2011-07-09 Thread Dumanshu
the string burns in an hour if lit from one end and string burns in 30 min if lit from both ends. This fact is based on - light up the string from either end it burns in 60 min. now heres the solution: Light up the first string from both ends and the second string from one end at the same time.

[algogeeks] Amazon Online question

2011-07-08 Thread Dumanshu
There are K pegs. Each peg can hold discs in decreasing order of radius when looked from bottom to top of the peg. There are N discs who have radius 1 to N; Given the initial configuration of the pegs and the final configuration of the pegs, output the moves required to transform from the initial

[algogeeks] find the integer

2011-07-08 Thread Dumanshu
given an array of intergers. find the any integer that occurs only once. Others might occur any no. of times. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from

[algogeeks] Re: find the integer

2011-07-08 Thread Dumanshu
no constraints but try to give the optimized solution and plz no hashing. On Jul 8, 7:02 pm, Dumanshu duman...@gmail.com wrote: given an array of intergers. find the any integer that occurs only once. Others might occur any no. of times. -- You received this message because you

[algogeeks] Re: Amazon

2011-07-07 Thread Dumanshu
how about this? given n milestones 1.find max number from the array and delete it. 2.now find any (x,y) both from the array such that x+y == max. 3. put min(x,y) in the front of output array, delete y from array and if(sizeof(output array)==(n-2)) put x also in front of output array and

[algogeeks] Re: Amazon

2011-07-07 Thread Dumanshu
Initially we can sort the array in O(nlogn) and then given a max value, find a pair (x,y) in O(n). here n is also of quadratic order if taken in terms of no. of milestones. On Jul 7, 5:52 pm, Dumanshu duman...@gmail.com wrote: how about this? given n milestones 1.find max number from

[algogeeks] Improve upon O(m^2)

2011-07-07 Thread Dumanshu
given two sorted arrays a[m] b[2*m], each contains m elements only. You need to merge those two arrays into second array b[2*m]. anything better than O(m^2) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

[algogeeks] Re: Merging Sorted Arrays

2011-07-07 Thread Dumanshu
@Radha: could u plz elaborate on getting the first n elements??? On Jul 8, 12:55 am, radha krishnan radhakrishnance...@gmail.com wrote: ok ! i got a O(n lgn) finally i don know exact complexity Let N = size of first array Find the first N smallest elements using one pointer in each array now

[algogeeks] Re: Some adobe interview questions.

2011-07-05 Thread Dumanshu
ans1. use counting sort for character array (0 to 255) then check for the second string if same or not. ans2. send 1 and 2, 1 comes back, send 10 and 5, 2 comes back, send 2 and 1 ans3. As vikas said, sum of digits should b 8. In that case the number must have a zero digit because 1st digit the

[algogeeks] Re: Some adobe interview questions.

2011-07-05 Thread Dumanshu
@Azhar: could u plz explain the q8. problem. On Jul 5, 12:13 pm, Azhar Hussain azhar...@gmail.com wrote: Q8 is a DP problem, here is the solution #include stdio.h #define MAX 125 #define VAL 6 int Min[MAX]; int N[VAL] = {5, 10, 20, 25, 50, 100}; int main(void) {     int i, j;    

[algogeeks] Re: Some adobe interview questions.

2011-07-05 Thread Dumanshu
will count as one traversal? Correct me if I am wrong? My approach: traverse storing each char in a string.when space encountered push the string in stack I am not sure how my solution is but it doesnt appears gud ryt now. On Tue, Jul 5, 2011  4:34 PM, Dumanshu duman...@gmail.com wrote

[algogeeks] Re: Interview Question

2011-07-02 Thread Dumanshu
xor all the elements of both arrays ==0 sum of 1st array == sum of 2nd array no. of elements in 1st == no. of elements in 2nd if the above conditions are met, they have the same set. m i missin sth? On Jul 3, 1:23 am, mittal mohitm.1...@gmail.com wrote: Given two arrays of numbers, find if each

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-07-01 Thread Dumanshu
.. if the value at prev center is small then next center won't skip positions it may be just the next one. so overall, it gives linear complexity. On Jul 1, 12:35 pm, hary rathor harry.rat...@gmail.com wrote: @Dumanshu; worst case O(n3) hai iska -- You received this message because you are subscribed

[algogeeks] Re: Longest substring 0's 1's

2011-07-01 Thread Dumanshu
@sunny: if a[i]==0 then 0,i is the solution suppose a[i]==a[j] ==0 now 0,i and 0,j is the solution. is i,j also the solution?? On Jul 1, 4:08 pm, sunny agrawal sunny816.i...@gmail.com wrote: String = 1 0 1 1 0 1 1 1. 1. make the  array = 1 -1 1 1 -1 1 1 1 2. after second operation array = 1 0

[algogeeks] Re: conditional compilation

2011-07-01 Thread Dumanshu
, himanshu kansal himanshukansal...@gmail.com wrote: If i do #if i==0 thn it vl cmpl it..means its tkng it as 0..bt why... On 7/1/11, Dumanshu duman...@gmail.com wrote: i think it will take a garbage value for i because these are preprocessor directives. On Jun 30, 4:46 pm, himanshu

[algogeeks] Re: conditional compilation

2011-07-01 Thread Dumanshu
In ur second code change int i=2 and run it. It would still print bye. check the result of preprocessor using -E flag. On Jun 30, 4:46 pm, himanshu kansal himanshukansal...@gmail.com wrote: 1 more thngif its possible to eval. variable expression lyk abv... thn... int i=2; #if i==2

[algogeeks] Re: Google Interview

2011-06-30 Thread Dumanshu
@Jitendra: where r u using k in the first call? On Jun 30, 8:56 am, Jitendra singh jsinghrath...@gmail.com wrote: kthlargest(a[],b[],lefta,righta,leftb,rightb,k) {   mida=lefta+(righta-lefta)/2;   midb=leftb+(rightb-leftb)/2;    if(a[mida]bmidb])      

[algogeeks] Re: Amazon - Longest palindrome in a string in O(n)

2011-06-30 Thread Dumanshu
heres the code: http://ideone.com/aiG1m using the algo from http://www.akalin.cx/2007/11/28/finding-the-longest-palindromic-substring-in-linear-time/ On Jun 21, 11:31 pm, Swathi chukka.swa...@gmail.com wrote: Does any one know how to return the Longest palindrome in a string in O(n). From

[algogeeks] Re: Google Interview

2011-06-30 Thread Dumanshu
check this code http://ideone.com/rX130 compares k/2 values of each array taking care of extremes. On Jun 24, 9:48 pm, Decipher ankurseth...@gmail.com wrote: Can anybody please explain how to solve this question with logarithmic time complexity ? Write the code/algorithm to find the k-th

[algogeeks] Re: conditional compilation

2011-06-30 Thread Dumanshu
i think it will take a garbage value for i because these are preprocessor directives. On Jun 30, 4:46 pm, himanshu kansal himanshukansal...@gmail.com wrote: 1 more thngif its possible to eval. variable expression lyk abv... thn... int i=2; #if i==2 printf(hi); #else printf(bye);    

[algogeeks] Re: Amazon - max substring

2011-06-29 Thread Dumanshu
I have used suffix arrays. Its easier to implement than trees. code here- http://ideone.com/kX8MV In case u find a test case givin wrong output plz do tell. On Jun 29, 9:54 pm, Swathi chukka.swa...@gmail.com wrote: Given a string (assume there no spaces or punctuations), write a code that

[algogeeks] Re: Amazon - max substring

2011-06-29 Thread Dumanshu
for the input doomdoomdoom output is 4 or 8? On Jun 30, 2:04 am, Dumanshu duman...@gmail.com wrote: I have used suffix arrays. Its easier to implement than trees. code here-http://ideone.com/kX8MV In case u find a test case givin wrong output plz do tell. On Jun 29, 9:54 pm, Swathi

[algogeeks] Re: Amazon - max substring

2011-06-29 Thread Dumanshu
if the output for the input doomdoomdoom is 8 then refer to http://ideone.com/kX8MV else if the output is 4 then refer to http://ideone.com/3tAKN the second one is having a higher complexity. ny suggestions? On Jun 29, 9:54 pm, Swathi chukka.swa...@gmail.com wrote: Given a string (assume there

[algogeeks] Re: Amazon - max substring

2011-06-29 Thread Dumanshu
O(n^2) and O(n^3) respectively. On Jun 30, 3:47 am, Dumanshu duman...@gmail.com wrote: if the output for the input doomdoomdoom is 8 then refer tohttp://ideone.com/kX8MV else if the output is 4 then refer tohttp://ideone.com/3tAKN the second one is having a higher complexity. ny suggestions

[algogeeks] Re: NEED ALGO IN TIME 0.00

2011-06-27 Thread Dumanshu
, Dumanshu duman...@gmail.com wrote: finally got it in 0.01 sec using all the optimizations i am aware of including what Wladimir had suggested. Now wat to do for 0.00??? heres my code- http://ideone.com/lsK8n please suggest if any further optimizations possible. On Jun 26, 2:21 am

[algogeeks] Re: NEED ALGO IN TIME 0.00

2011-06-26 Thread Dumanshu
@Dan: see, that is not the point. We are just looking for a better solution not just an algorithm which fetches us 0.00 time given the SPOJ conditions. Actually we are not worried about the compiler stuff because its all relative. Some other person on this SPOJ platform has submitted the code

[algogeeks] Re: puzzle

2011-06-26 Thread Dumanshu
These type of solutions require to think in binary. First of all leave the last one because if we don't find a poisoned bottle in first 5 then it means the last one is poisoned. So 5 can be expressed using 3 bits. these 3 bits will correspond to mice... 1 indicates the mice drinks and 0 indicates

[algogeeks] Re: NEED ALGO IN TIME 0.00

2011-06-25 Thread Dumanshu
see i got 0.07 sec as the time after using counting sort.. because the hotness scale is 0-10 so i used an array of 11 ints to count the no. of occurrences. But i m nt able to further reduce this. ny suggestions? theres a comment on the problem: On an interesting side note: the maximising

[algogeeks] Re: NEED ALGO IN TIME 0.00

2011-06-25 Thread Dumanshu
in logic. wat do u think? On Jun 26, 12:25 am, Dumanshu duman...@gmail.com wrote: see i got 0.07 sec as the time after using counting sort.. because the hotness scale is 0-10 so i used an array of 11 ints to count the no. of occurrences. But i m nt able to further reduce this. ny suggestions

[algogeeks] Re: NEED ALGO IN TIME 0.00

2011-06-25 Thread Dumanshu
finally got it in 0.01 sec using all the optimizations i am aware of including what Wladimir had suggested. Now wat to do for 0.00??? heres my code- http://ideone.com/lsK8n please suggest if any further optimizations possible. On Jun 26, 2:21 am, Dumanshu duman...@gmail.com wrote: Ok, it seems

[algogeeks] Re: Google Question

2011-06-22 Thread Dumanshu
@Piyush: could u plz post the link to the same? On Jun 22, 2:15 pm, Piyush Sinha ecstasy.piy...@gmail.com wrote: This question has been discussed over here once...It was concluded that this can be solved in O(n) if we know there is a fixed range up to which the elements keep on increasing and

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread Dumanshu
Dynamic programming using memoization is the best one i think. On Jun 21, 3:17 am, PRAMENDRA RATHi rathi prathi...@gmail.com wrote: what is the shortest algo to find the value of nCr if both n,r100... - PRAMENDRA RATHI NIT ALLAHABAD -- You

[algogeeks] Re: finding vlaue of nCr

2011-06-21 Thread Dumanshu
@Sunny: the value can still overflow because Using the while loop u r dividing the res value whenever possible. so the while checks if the current j divides res or not. What if current res value is not divisible by that particular j ... it will multiply by i for next res value and it will keep

[algogeeks] Re: google interview c testing

2011-06-18 Thread Dumanshu
new and delete are functions available in C++ and not in C. m i right? On Jun 17, 2:34 pm, rohit rajuljain...@gmail.com wrote: how to free memory allocated to an array with new function? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

[algogeeks] Re: How to use asm in spoj

2011-06-18 Thread Dumanshu
Yes SPOJ uses the nasm assembler. On Jun 18, 7:02 am, saurabh singh saurab...@gmail.com wrote: I am using standard gcc 4.3.2 and the code does not requires any flag to be required.I also checked the alias if gcc has been aliased to be used with some option,but that was not the case.My

[algogeeks] Re: Mutex

2011-06-18 Thread Dumanshu
can use either. Now plz give me some examples where mutex is preferred over binary semaphore and vice-versa. Thanks Dumanshu On Jun 18, 1:58 am, DK divyekap...@gmail.com wrote: @Dumanshu/@Ankit: Of course mutexes can be made to work between processes (it's an implementation detail

[algogeeks] Re: Finding the min gap in 3 arrays

2011-06-18 Thread Dumanshu
. Is this what you are trying to do here? sorry i dont get your algo. Thanks Dumanshu On Jun 18, 12:06 am, Ashish Goel ashg...@gmail.com wrote: say the arrays are a 6,7,9 b 3,4,5 c 1,2,8 the merged array would be 1c 2c 3a 4b 5b 6a 7a 8c 9a 1c,2c cant be compared as they are from

[algogeeks] Re: How to use asm in spoj

2011-06-18 Thread Dumanshu
It does matter. suppose u write the c code and the compiler generates assembly level code later u get machine code which runs. here in this process many optimizations can be employed which are not done by gcc. So including asm code in ur c code can actually make ur code to run very fast provided u

[algogeeks] Finding the min gap in 3 arrays

2011-06-17 Thread Dumanshu
U have got 3 sorted arrays A1 A2 and A3 having m n and p elements respectively. A gap of 3 arrays is defined to be max distance between 3 nos if they are put on a no line say u pick three 2 12 and 7 then the gap is 10. Now u have to find an efficient way of chosing 3 nos from these 3 seperate

  1   2   >