Re: [algogeeks] Interview Question

2013-04-26 Thread Nishant Pandey
the code is simply utilizing the xor property as u know xor sets on odd one so, if any array would have numbers odd times repeated their bit will only stay in xor operation else will get nulify. so in first loop bit of 1 and 3 are set, to seperate them we need to divide them using any of their se

Re: [algogeeks] Interview Question

2013-04-26 Thread Krishnan
an useful link http://stackoverflow.com/questions/7338070/finding-an-element-in-an-array-where-every-element-is-repeated-odd-number-of-tim On Fri, Apr 19, 2013 at 11:30 PM, kartik n wrote: > Hi Nishant i did not understand the code can u please describe a bit > > Thanks > > > On Fri, Apr 19, 2

Re: [algogeeks] Interview Question

2013-04-19 Thread kartik n
Hi Nishant i did not understand the code can u please describe a bit Thanks On Fri, Apr 19, 2013 at 10:48 AM, rahul sharma wrote: > search the previous posts before posting > > search for > [algogeeks] Amazon Interview Question > you will get this > > -- > You received this message because you

Re: [algogeeks] Interview Question

2013-04-19 Thread rahul sharma
search the previous posts before posting search for [algogeeks] Amazon Interview Question you will get this -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To unsubscribe from this group and stop receiving emails from it, send an email to a

Re: [algogeeks] Interview Question

2013-04-19 Thread Nishant Pandey
int main() { int a[] = {1,2,2,3,3,3,4,4}; int size = sizeof(a)/sizeof(a[0]); int xorr=0; for(int i=0;iwrote: > In an array, some numbers occur only once, some numbers occur twice, only > one number occur thrice. Find the number occuring thrice ? Space complexity > O(1) Time Complexity O(n). We s

Re: [algogeeks] INTERVIEW QUESTION

2012-10-30 Thread Saurabh Kumar
you are right. k is the edit distance we are searching for and a critical parameter. In short you can say- k represents how much error(in terms of edit-distance) you want to tolerate for between document word 'w' and your suggestion. since our data structure can answer queries for e.g. "Find all wo

Re: [algogeeks] INTERVIEW QUESTION

2012-10-27 Thread payal gupta
the question mentioned is as it isi just copy pasted it here. @saurabh thanx for the explainaton of the cube problem i guess that is an appropriate soln for the question. and for the other question on detection of typos and suggestion i would like to know to know what 'k' in your explaination

Re: [algogeeks] INTERVIEW QUESTION

2012-10-27 Thread Saurabh Kumar
Firstly, that question is missing a lot of details. In absence of those details I'm going to make soem assumptions: 1. cube is odd lengthed, so that we can define a unique center of cube. 2. While traversing from a cell(x, y, z) we can only move into any of the 6 adjacent cells[x(+-)1, y(+-)1, z(+-

Re: [algogeeks] INTERVIEW QUESTION

2012-10-27 Thread Saurabh Kumar
could you please share the link? coz at first glance a Trie looks like a bad choice for this task. I'd go with the Levenshtein distance and a kd-tree. First implement the Levenshtein distance algorithm to calculate the edit distance of two strings. Second, since Levenshtein distance qualifies as a

Re: [algogeeks] INTERVIEW QUESTION

2012-10-26 Thread payal gupta
Sorry ,posted the wrong question initially actually i needed the algo for this question. Thanx. On Saturday, October 27, 2012 7:04:10 AM UTC+5:30, raghavan wrote: > > By any chance did you read the new blog post by Gayle Laakmaan.. > > I guess to detect typos we can use some sort of Trie imple

Re: [algogeeks] INTERVIEW QUESTION

2012-10-26 Thread Kartik Sachan
@payal why u need this..??...:P:P -- 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 this group, send email to algogeeks+unsubscr...@googlegroups.com. For more

Re: [algogeeks] INTERVIEW QUESTION

2012-10-26 Thread Raghavan
By any chance did you read the new blog post by Gayle Laakmaan.. I guess to detect typos we can use some sort of Trie implementation.. On Fri, Oct 26, 2012 at 7:50 PM, payal gupta wrote: > >Given a cube with sides length n, write code to print all possible > paths from the center to the su

Re: [algogeeks] Interview Question based on histogram

2012-05-17 Thread payal gupta
//A <-area of the cell of histogram // volarr[] <-holds the vol of water already present at particular index void fn(int index,int volpoured) { int vcapacity=A*heightarr[index]; if(volpoured+volarr[index]vcapacity) { volpoured-=vcapacity-volarr[index]; volarr[index]=vcapacity; // if the height of t

Re: [algogeeks] Interview Question based on histogram

2012-05-17 Thread payal gupta
hope this works.. http://ideone.com/XSJRJ On Fri, May 18, 2012 at 8:20 AM, Bhaskar Kushwaha < bhaskar.kushwaha2...@gmail.com> wrote: > It depends on which column you are pouring the water. > For example > If you choose the shortest column to pour the water then only that column > will be filled w

Re: [algogeeks] Interview Question based on histogram

2012-05-17 Thread Bhaskar Kushwaha
It depends on which column you are pouring the water. For example If you choose the shortest column to pour the water then only that column will be filled with water. Please correct me if I am wrong. On Thu, May 17, 2012 at 11:27 AM, Nikhil Agarwal wrote: > Imagine that you have an histogram sto

Re: [algogeeks] Interview question

2011-11-29 Thread saurabh singh
@anup an example what the question meant if(x==1||x==0) { /*stuff*/ } On Wed, Nov 30, 2011 at 11:07 AM, Anup Ghatage wrote: > If I have understood the question correctly, Infinite :P > > You can have infinite ways to express 0 or 1 given that the ways are > differentiable amongst themselves. >

Re: [algogeeks] Interview question

2011-11-29 Thread Anup Ghatage
If I have understood the question correctly, Infinite :P You can have infinite ways to express 0 or 1 given that the ways are differentiable amongst themselves. An even number can be considered as a 0 and an odd number as a 1... etc On Wed, Nov 30, 2011 at 8:37 AM, Nitin Garg wrote: > *What a

Re: [algogeeks] Interview question

2011-10-31 Thread shady
from where does the index starts, 0 or 1 ? in this, array to be moved is {7, 5, 8} ? and source array the destination | | {9, 7, 5, 8, 1, 5, 4, 8, 10, 1} please explain move_set o

Re: [algogeeks] interview question

2011-07-20 Thread surender sanke
needs explicit function specialisation. be careful with constant strings. T Add(T a, T b) {return a+b ;} template<> char* Add char* a, char* b) {return strcat((char*)a,b); } surender On Tue, Jul 19, 2011 at 10:17 PM, Anika Jain wrote: > here T becomes char *.. u r trying to add two addreses

Re: [algogeeks] interview question

2011-07-19 Thread Anika Jain
here T becomes char *.. u r trying to add two addreses here... On Tue, Jul 19, 2011 at 9:46 PM, nidhi jain wrote: > Consider a c++ template funtion > template > T& Add(T a, T b) > {return a+b ;} > if this function is called as T c = Add("SAM", "SUNG"); what will > happen? What is the problem in t

Re: [algogeeks] Interview Question: Puzzle: Probability

2011-06-22 Thread Vishal Jain
Navneet, Your answer is correct, it would have been great if you could have explained it for others. I myself took good time to understand it... Here is the answer http://exploreriddles.blogspot.com/2011/06/interview-questions-puzzle.html To maximize the chances of retrieving Red Ball, it is m

Re: [algogeeks] Interview Question: Puzzle: Probability

2011-06-14 Thread Navneet Gupta
Put one red ball in one jar and rest 99 balls in other jar. Probability in that case is 1/2*1 + 1/2*49//99 On Tue, Jun 14, 2011 at 7:45 PM, Vishal Jain wrote: > Folks, > > This question was asked during a screening process of a product based > company. Please answer. > > http://exploreriddles.b

Re: [algogeeks] Interview Question

2011-04-11 Thread Umer Farooq
Ankur, you are rite. He mentioned that we may not know what the data might be. And yes, I agree that he kept the restriction because we may not know what the data is. In that case, I guess bit by bit copying of data from the next node to the current node (it is possible since both the nodes are of

Re: [algogeeks] Interview Question

2011-04-08 Thread ankur bhardwaj
For the 2nd ques, wat i think is the interviewer has kept the restriction of not moving the data since you may have a linked list about which you donot have much information about the structure of the node of the list(only know about the next pointer) and hence you cannot move the data. For that, y

Re: [algogeeks] Interview Question

2011-04-07 Thread Abhishek Mallick
@ your name last name : please read the question carefully. * * * * On Fri, Apr 8, 2011 at 12:11 AM, your name last name wrote: > Moving the data is unnecessary if in case the whole pointer shifting is > meant for the entire node and not for individual elements of the node. > temp ->next = ( temp

Re: [algogeeks] Interview Question

2011-04-07 Thread your name last name
Moving the data is unnecessary if in case the whole pointer shifting is meant for the entire node and not for individual elements of the node. temp ->next = ( temp -> next ) -> next the above statement is more than enough to remove the midlle node from the list... -- You received this message be

Re: [algogeeks] Interview Question

2011-04-07 Thread Anurag atri
@All yeah my solution does move data ... I am very interested in knowing a solution that moves no data , someone please come up with a solution . On Thu, Apr 7, 2011 at 9:23 PM, balaji a wrote: > lets say there are two pointers - temp1,temp2 and the start of the node is > head > now, > tem

Re: [algogeeks] Interview Question

2011-04-07 Thread balaji a
lets say there are two pointers - temp1,temp2 and the start of the node is head now, temp1=head; temp2=head->next; temp1->next=temp2->next; now temp1 points to the first node and the temp2 points to the second node(which got deleted from the list). On Thu, Apr 7, 2011 at 5:43 PM, U

Re: [algogeeks] Interview Question

2011-04-07 Thread Kamakshii Aggarwal
1st case: if ptr points to the first node, then ptr->next=(ptr->next)->next will do. 2nd case:i think tehre has to be movement of data from third node to the second node. On 4/4/11, Umer Farooq wrote: > Hello friends, > > The following question has appeared in two top companies of my city. I'd >

Re: [algogeeks] Interview Question

2011-04-07 Thread Umer Farooq
So, is there any other way of doing this? I did it the way anurag did it; but the interviewer asked me to do it without moving the data. On Thu, Apr 7, 2011 at 6:38 PM, Abdul Rahman Shariff wrote: > @akash ur rite u cannot move data there > > > On Thu, Apr 7, 2011 at 2:35 PM, Akash Mukherjee wrot

Re: [algogeeks] Interview Question

2011-04-07 Thread Umer Farooq
in the first case temp ->next = ( temp -> next ) -> next . The middle node will become orphan and it won't be deleted, I guess. in second case I did it the same way. Then he asked me to solve this without moving the data? On Wed, Apr 6, 2011 at 8:03 PM, Anurag atri wrote: > in case you are giv

Re: [algogeeks] Interview Question

2011-04-07 Thread Kamakshii Aggarwal
@anurag:the second case of yours requires movement of data if I am not wrong... @umer farooq:pls calrify what does movement of data mean? On Wed, Apr 6, 2011 at 8:33 PM, Anurag atri wrote: > in case you are given a pointer to the first node simply do > temp ->next = ( temp -> next ) -> next . > i

Re: [algogeeks] Interview Question

2011-04-07 Thread Umer Farooq
That can be moved. Basically, he is trying to convey that move the data of temp->next to temp. That's perfectly fine. On Thu, Apr 7, 2011 at 2:05 PM, Akash Mukherjee wrote: > @ anurag > > temp -> data = ( temp -> next ) -> data ; > > but data cannot be moved, ryt?? > > On 4/6/11, Anurag atri wr

Re: [algogeeks] Interview Question

2011-04-07 Thread Abdul Rahman Shariff
@akash ur rite u cannot move data there On Thu, Apr 7, 2011 at 2:35 PM, Akash Mukherjee wrote: > @ anurag > > temp -> data = ( temp -> next ) -> data ; > > but data cannot be moved, ryt?? > > On 4/6/11, Anurag atri wrote: > > in case you are given a pointer to the first node simply do > > temp

Re: [algogeeks] Interview Question

2011-04-07 Thread Akash Mukherjee
@ anurag temp -> data = ( temp -> next ) -> data ; but data cannot be moved, ryt?? On 4/6/11, Anurag atri wrote: > in case you are given a pointer to the first node simply do > temp ->next = ( temp -> next ) -> next . > if you are given a pointer to the second node do , > temp -> data = ( temp

Re: [algogeeks] Interview Question

2011-04-06 Thread Anurag atri
in case you are given a pointer to the first node simply do temp ->next = ( temp -> next ) -> next . if you are given a pointer to the second node do , temp -> data = ( temp -> next ) -> data ; temp -> next = NULL ; correct me if I am wrong . On Mon, Apr 4, 2011 at 9:48 PM, Umer Farooq wrote: >

Re: [algogeeks] Interview question amazon

2011-01-15 Thread Ashish Goel
int hasPathSum(struct node* node, int sum) { // return true if we run out of tree and sum==0 if (node == NULL) { return(sum == 0); } else { // otherwise check both subtrees int subSum = sum - node->data; return(hasPathSum(node->left, subSum) || hasPathSum(node->righ

Re: [algogeeks] Interview Question

2011-01-11 Thread juver++
This problem has DP solution in O(n^2) I think. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups

Re: [algogeeks] Interview Question

2011-01-11 Thread Vikas Singh
I agree with the trie solution. But now how do you generalise it for K. I mean a word can be made from k other words. On Wed, Jan 12, 2011 at 12:53 AM, juver++ wrote: > If you represent dictionary as a hash table, lookup costs you O(L) at > least! > Cause you need to calculate hash for the strin

Re: [algogeeks] Interview Question

2011-01-11 Thread juver++
If you represent dictionary as a hash table, lookup costs you O(L) at least! Cause you need to calculate hash for the string. But for the trie it is O(L) in a worst case. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group,

Re: [algogeeks] Interview Question

2011-01-11 Thread manoj lalavat
words and...so on... on dictionaries lookup is O(1) now think abt complexity... pass1 for (1 to N) example here N=strlen(newspaper) other passes are also same... On Tue, Jan 11, 2011 at 8:07 PM, juver++ wrote: > What do you mean by N? > If N - size of the dictionary. And L- maximum length o

Re: [algogeeks] Interview Question

2011-01-11 Thread juver++
What do you mean by N? If N - size of the dictionary. And L- maximum length of the words then above algo is O(N*L) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscrib

Re: [algogeeks] Interview Question

2011-01-11 Thread manoj lalavat
how abt this.. Pass1 = look whether words like n,ne,new,news.exist or not...store information in some array like n is not found so is ne but new is found and news is found so array will be like 0,0,1,1. Pass2 = do d same from from the end... r,er,per,aper,paper 0,0,1,0,1 P

Re: [algogeeks] Interview Question

2011-01-11 Thread Vikas Singh
Wouldn't that be O(n2) . what if n, ne, new, news, newsp etc all are valid words ? Cant it be optimized? On Tue, Jan 11, 2011 at 6:27 PM, juver++ wrote: > Use trie (or similar DS). > For each word, try to find second part of the target in a linear time > O(length). > > -- > You received this mes

Re: [algogeeks] Interview Question

2011-01-11 Thread Vikas Singh
please ignore earlier message...it was supposed to be a private message.. On Tue, Jan 11, 2011 at 6:52 PM, Vikas Singh wrote: > lalla..bruteforce na bako.. :P > > > On Tue, Jan 11, 2011 at 6:07 PM, manoj lalavat wrote: > >> you can optimize BF >> >> newspaper >> >> first word you will search >> >

Re: [algogeeks] Interview Question

2011-01-11 Thread Vikas Singh
lalla..bruteforce na bako.. :P On Tue, Jan 11, 2011 at 6:07 PM, manoj lalavat wrote: > you can optimize BF > > newspaper > > first word you will search > > n > > then > > ne > > then > > new > > then news..and so onif at any point of time first word exist in > dictionary then only see whether

Re: [algogeeks] Interview Question

2011-01-11 Thread juver++
Use trie (or similar DS). For each word, try to find second part of the target in a linear time O(length). -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from

Re: [algogeeks] Interview Question

2011-01-11 Thread manoj lalavat
you can optimize BF newspaper first word you will search n then ne then new then news..and so onif at any point of time first word exist in dictionary then only see whether the word with the remaining characters exist in the dictionary or not. On Tue, Jan 11, 2011 at 5:57 PM, Vikas Si

Re: [algogeeks] Interview question amazon

2011-01-04 Thread ADITYA KUMAR
problem has many properties like its a BST with parent pointer we shud think of such a solution which uses its both property If we will think abt the brute force recursive solution its complexity will be O(no_of_nodes*height) which can be made more efficient by putting some restrictions in each r

Re: [algogeeks] Interview question amazon

2010-12-27 Thread mohit ranjan
any hint for below question ? Mohit On Sun, Dec 26, 2010 at 10:38 PM, MAC wrote: > you are given a bst where each node has a int value , parent pointer , and > left and right pointers , write a function to find a path with a given sum > value. Path can go from left subtree tree , include roo

Re: [algogeeks] interview question

2009-11-04 Thread daizi sheng
I guess this is just a *program* problem, not even including any algorithm problem. Even from viewer of c++ programmer, I think you should refer any classic c++ tutorial for it, instead of asking it online. It is an interview problem, and it can be find on any c++ book. Just use some time to find i