[algogeeks] Re: Traverse a 2-D array of strings
@atul007, number of rows represent number of tokenized strings.How do i know the number of tokenized strings? It depends upon input string and delimiter On Saturday, 14 July 2012 22:45:46 UTC+5:30, Abhi wrote: I have written a mystrtok function which takes a string and a delimiter as argument and returns an array of tokenized strings.But i don't know how to traverse that array Here is my code:- char string[50] = asdf.sdf.sdf.sdf.wer.sfd.df; char delim = '.'; char **result = mystrtok( string , delim); for (int i=0; ??? ; i++) //what to write in condition part printf(%s,result[i]); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/exXJLYEOcXwJ. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Appropriate data structure
Min or max heap accordingly. This will do the job in O(log n) time. On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar algorithm.i...@gmail.comwrote: A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days. What data structures would you use for storing and retrieving ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/2AhV1Xn3jD8J. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Traverse a 2-D array of strings
1) you can count . in the input string +1 = number of tokens 2) you can pass by reference a variable to mystrtok(string,delim,len); in your function at the end you can store count *len=count; and this len can be used in the loop. for(i=0;ilen;i++) On 7/15/12, Abhi abhi120...@gmail.com wrote: @atul007, number of rows represent number of tokenized strings.How do i know the number of tokenized strings? It depends upon input string and delimiter On Saturday, 14 July 2012 22:45:46 UTC+5:30, Abhi wrote: I have written a mystrtok function which takes a string and a delimiter as argument and returns an array of tokenized strings.But i don't know how to traverse that array Here is my code:- char string[50] = asdf.sdf.sdf.sdf.wer.sfd.df; char delim = '.'; char **result = mystrtok( string , delim); for (int i=0; ??? ; i++) //what to write in condition part printf(%s,result[i]); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/exXJLYEOcXwJ. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks]
#include stdio.h main() { char * str = hello; char * ptr = str; char least = 127; while (*ptr++) least = (*ptrleast ) ?(*ptr) :(least); printf(%d,least); getch(); } in this ques i got o/p is 0(no doubt) but i have a doubt in why every time least is getting 101-'e' as the value. why are ascii values of llo not assigned in least. please someone explain. -- Vindhya Chhabra -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Traverse a 2-D array of strings
@atul007, but that doesn't work for extreme cases like .sdlf.sfd.sd.f and sdf..sfdsf.sfddf On 7/15/12, atul anand atul.87fri...@gmail.com wrote: 1) you can count . in the input string +1 = number of tokens 2) you can pass by reference a variable to mystrtok(string,delim,len); in your function at the end you can store count *len=count; and this len can be used in the loop. for(i=0;ilen;i++) On 7/15/12, Abhi abhi120...@gmail.com wrote: @atul007, number of rows represent number of tokenized strings.How do i know the number of tokenized strings? It depends upon input string and delimiter On Saturday, 14 July 2012 22:45:46 UTC+5:30, Abhi wrote: I have written a mystrtok function which takes a string and a delimiter as argument and returns an array of tokenized strings.But i don't know how to traverse that array Here is my code:- char string[50] = asdf.sdf.sdf.sdf.wer.sfd.df; char delim = '.'; char **result = mystrtok( string , delim); for (int i=0; ??? ; i++) //what to write in condition part printf(%s,result[i]); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/exXJLYEOcXwJ. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Appropriate data structure
It says K days if you keep heap the order of values gets disturbed. How are last k values accessed then? On Sunday, 15 July 2012 12:46:02 UTC+5:30, adarsh kumar wrote: Min or max heap accordingly. This will do the job in O(log n) time. On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar algorithm.i...@gmail.comwrote: A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days. What data structures would you use for storing and retrieving ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/2AhV1Xn3jD8J. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/peWhqjKLIH8J. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Appropriate data structure
I think stack would solve the purpose. please comment. On Sun, Jul 15, 2012 at 5:42 PM, enchantress elaenjoy...@gmail.com wrote: It says K days if you keep heap the order of values gets disturbed. How are last k values accessed then? On Sunday, 15 July 2012 12:46:02 UTC+5:30, adarsh kumar wrote: Min or max heap accordingly. This will do the job in O(log n) time. On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar algorithm.i...@gmail.comwrote: A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days. What data structures would you use for storing and retrieving ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/** msg/algogeeks/-/2AhV1Xn3jD8Jhttps://groups.google.com/d/msg/algogeeks/-/2AhV1Xn3jD8J . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/peWhqjKLIH8J. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Appropriate data structure
Oh ya sorry. I thought we have to retrieve kth min and max, in which case heap can be used. Here, we can either use stack or map. Map can be from a date(which increases by 1 daily) to a value, as only one value is received per day. Keeping in mind memory constraints, stack is better. Map is an otherwise safe solution. regards. On Sun, Jul 15, 2012 at 6:24 PM, Navin Kumar algorithm.i...@gmail.comwrote: I think stack would solve the purpose. please comment. On Sun, Jul 15, 2012 at 5:42 PM, enchantress elaenjoy...@gmail.comwrote: It says K days if you keep heap the order of values gets disturbed. How are last k values accessed then? On Sunday, 15 July 2012 12:46:02 UTC+5:30, adarsh kumar wrote: Min or max heap accordingly. This will do the job in O(log n) time. On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar algorithm.i...@gmail.comwrote: A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days. What data structures would you use for storing and retrieving ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/** msg/algogeeks/-/2AhV1Xn3jD8Jhttps://groups.google.com/d/msg/algogeeks/-/2AhV1Xn3jD8J . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/peWhqjKLIH8J. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Traverse a 2-D array of strings
your mystrtok() must be extracting string...so i dont this so there is any problem in that. if you dont want to pass extra parameter to the function then still it can be doneyou can check if there is string after a . delim On 7/15/12, Abhishek Sharma abhi120...@gmail.com wrote: @atul007, but that doesn't work for extreme cases like .sdlf.sfd.sd.f and sdf..sfdsf.sfddf On 7/15/12, atul anand atul.87fri...@gmail.com wrote: 1) you can count . in the input string +1 = number of tokens 2) you can pass by reference a variable to mystrtok(string,delim,len); in your function at the end you can store count *len=count; and this len can be used in the loop. for(i=0;ilen;i++) On 7/15/12, Abhi abhi120...@gmail.com wrote: @atul007, number of rows represent number of tokenized strings.How do i know the number of tokenized strings? It depends upon input string and delimiter On Saturday, 14 July 2012 22:45:46 UTC+5:30, Abhi wrote: I have written a mystrtok function which takes a string and a delimiter as argument and returns an array of tokenized strings.But i don't know how to traverse that array Here is my code:- char string[50] = asdf.sdf.sdf.sdf.wer.sfd.df; char delim = '.'; char **result = mystrtok( string , delim); for (int i=0; ??? ; i++) //what to write in condition part printf(%s,result[i]); -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/exXJLYEOcXwJ. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Abhishek Sharma Under-Graduate Student, PEC University of Technology -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks]
please someone explain On Sun, Jul 15, 2012 at 3:54 PM, vindhya chhabra vindhyachha...@gmail.comwrote: #include stdio.h main() { char * str = hello; char * ptr = str; char least = 127; while (*ptr++) least = (*ptrleast ) ?(*ptr) :(least); printf(%d,least); getch(); } in this ques i got o/p is 0(no doubt) but i have a doubt in why every time least is getting 101-'e' as the value. why are ascii values of llo not assigned in least. please someone explain. -- Vindhya Chhabra -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Vindhya Chhabra -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks]
on first iteration *ptr == 'h' so it will enter in the loop. ptr++ -- *ptr == 'e'; comparing *ptr with least i.e 127 (ascii) *ptr will be 'e' now; 2nd iteration *ptr == e ptr++ - *ptr = 'l' comparing 'e' with 'l' and 'e' will be assgined to least and so on; coz 'e' has the lowest ascii value in given set of characters so least will never change when first time it is assgined to 'e'; -- Anshuman Mishra | Software Development Engineer | Amazon -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Appropriate data structure
@Navin: I would use a linked list containing the value and date, with extra pointers to the next larger element and the next smaller element. New items are inserted at the head of the list. Then the next larger pointer is updated by searching the list of next larger pointers, beginning with the original head's next larger pointer, for the first element larger than the current element; if no larger element is found, set the next larger pointer to null. The next smaller pointer is updated similarly. When a request is made, the list formed by the next larger pointers, starting with the head node, is searched for the last item whose date differs from the current date by k, and similarly the list formed by the next smaller pointers. Dave On Saturday, July 14, 2012 2:55:48 PM UTC-5, Navin Kumar wrote: A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days. What data structures would you use for storing and retrieving ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/57HnzcO4goUJ. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks]
@Vindhya every time least is getting 101-'e' as the value. and not llo as the statement least = (*ptrleast ) ?(*ptr) :(least); is equivalent to if(*ptrleast) least=*ptr; so firstly it compares 127 with 'e' and least ='e' in next iteration , it compares l and e, so agn least = 'e' in next iteration , it compares l and e, so agn least = 'e' in next iteration , it compares o and e, so agn least = 'e' in next iteration , it compares null and e, so least = 0 i hope this will clarify your doubts On Sun, Jul 15, 2012 at 11:57 PM, vindhya chhabra vindhyachha...@gmail.comwrote: please someone explain On Sun, Jul 15, 2012 at 3:54 PM, vindhya chhabra vindhyachha...@gmail.com wrote: #include stdio.h main() { char * str = hello; char * ptr = str; char least = 127; while (*ptr++) least = (*ptrleast ) ?(*ptr) :(least); printf(%d,least); getch(); } in this ques i got o/p is 0(no doubt) but i have a doubt in why every time least is getting 101-'e' as the value. why are ascii values of llo not assigned in least. please someone explain. -- Vindhya Chhabra -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Vindhya Chhabra -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks]
thanks, i got it nw. On Mon, Jul 16, 2012 at 12:45 AM, ashish jain ashishjainco...@gmail.comwrote: @Vindhya every time least is getting 101-'e' as the value. and not llo as the statement least = (*ptrleast ) ?(*ptr) :(least); is equivalent to if(*ptrleast) least=*ptr; so firstly it compares 127 with 'e' and least ='e' in next iteration , it compares l and e, so agn least = 'e' in next iteration , it compares l and e, so agn least = 'e' in next iteration , it compares o and e, so agn least = 'e' in next iteration , it compares null and e, so least = 0 i hope this will clarify your doubts On Sun, Jul 15, 2012 at 11:57 PM, vindhya chhabra vindhyachha...@gmail.com wrote: please someone explain On Sun, Jul 15, 2012 at 3:54 PM, vindhya chhabra vindhyachha...@gmail.com wrote: #include stdio.h main() { char * str = hello; char * ptr = str; char least = 127; while (*ptr++) least = (*ptrleast ) ?(*ptr) :(least); printf(%d,least); getch(); } in this ques i got o/p is 0(no doubt) but i have a doubt in why every time least is getting 101-'e' as the value. why are ascii values of llo not assigned in least. please someone explain. -- Vindhya Chhabra -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Vindhya Chhabra -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Vindhya Chhabra -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Directi Interview Ques
two arrays are suppose x[n], y[n]; take a function f( x(i, n), y(j, n) , 0) -- taking x[i] as a first element of merged array then max sum; f( x(i, n), y(j, n), 1) -- taking y[j] as a first element of merged array then max sum; f( x(i, n), y(j, n) ,0) = max( { x[i] * x[i+1] + f( x(i+1, n), y(j, n), 0) }, { x[i] * y[j] + f( x(i+1, n), y(j, n), 1 ) } ); f( x(i, n), y(j, n) ,1) = max( { x[i] * y[j] + f( x(i, n), y(j+1, n), 0) }, { y[j] * y[j+1] + f( x(i, n), y(j+1, n), 1 ) } ); final sol = max ( f( x(0, n), y(0, n) ,0), f( x(0, n), y(0, n) ,1) ); Now it's looking a very simple *dp *problem with O(n^2) time and space complexity. :) -- Anshuman Mishra | Software Development Engineer | Amazon -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Appropriate data structure
I think by using min/max heap we can fetch the kth largest/smallest data from the heap. But here there is one more point how to ensure that the data is smallest in last kth day. Here you can use interval/segment(augmented version of heap tree) tree, where u can store the interval/segment on the basis of date and retrieve the same information. On Sunday, 15 July 2012 12:46:02 UTC+5:30, adarsh kumar wrote: Min or max heap accordingly. This will do the job in O(log n) time. On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar algorithm.i...@gmail.comwrote: A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days. What data structures would you use for storing and retrieving ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/2AhV1Xn3jD8J. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/ypiCXt9_1BQJ. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Amazon Interview Question
For the series like 2,4,3,9,4,16,5,25 ur algo runs in o(n*n/2) =o(n^2) On Friday, 13 July 2012 13:16:50 UTC+5:30, jatin wrote: 1)Find product of the array and store it in say prod o(n) and o(1) 2)now traverse the array and check if static int i; tag: while(in) if( prod %(ar[i]*arr[i]*arr[i] ) ==0) break; //this may be the required element //e-o-while //now check is this is the element that is occuring three times o(n) if(number is not the required one then) goto tag; On Thursday, 12 July 2012 10:55:02 UTC+5:30, algo bard wrote: Given an array of integers where some numbers repeat once, some numbers repeat twice and only one number repeats thrice, how do you find the number that gets repeated 3 times? Does this problem have an O(n) time and O(1) space solution? No hashmaps please! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/C-nyIi38SN0J. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Appropriate data structure
agree with naveen On Sun, Jul 15, 2012 at 6:24 PM, Navin Kumar algorithm.i...@gmail.comwrote: I think stack would solve the purpose. please comment. On Sun, Jul 15, 2012 at 5:42 PM, enchantress elaenjoy...@gmail.comwrote: It says K days if you keep heap the order of values gets disturbed. How are last k values accessed then? On Sunday, 15 July 2012 12:46:02 UTC+5:30, adarsh kumar wrote: Min or max heap accordingly. This will do the job in O(log n) time. On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar algorithm.i...@gmail.comwrote: A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days. What data structures would you use for storing and retrieving ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/** msg/algogeeks/-/2AhV1Xn3jD8Jhttps://groups.google.com/d/msg/algogeeks/-/2AhV1Xn3jD8J . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/peWhqjKLIH8J. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Amazon Interview Question
If we can retrieve ith prime efficiently, we can do the following... 1.maintain a prod=1, start from 1st element, say a[0]=n find n th prime 2.check if (prod% (ith_prime * ith_prime )==0) then return i; else prod=prod*ith_prime; 3.repeat it till end On Thursday, 12 July 2012 10:55:02 UTC+5:30, algo bard wrote: Given an array of integers where some numbers repeat once, some numbers repeat twice and only one number repeats thrice, how do you find the number that gets repeated 3 times? Does this problem have an O(n) time and O(1) space solution? No hashmaps please! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/TSPSKlD0FDsJ. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Appropriate data structure
Stack will do it... and min or max can be even retrieved in O(1) ... On Sun, Jul 15, 2012 at 6:36 PM, adarsh kumar algog...@gmail.com wrote: Oh ya sorry. I thought we have to retrieve kth min and max, in which case heap can be used. Here, we can either use stack or map. Map can be from a date(which increases by 1 daily) to a value, as only one value is received per day. Keeping in mind memory constraints, stack is better. Map is an otherwise safe solution. regards. On Sun, Jul 15, 2012 at 6:24 PM, Navin Kumar algorithm.i...@gmail.comwrote: I think stack would solve the purpose. please comment. On Sun, Jul 15, 2012 at 5:42 PM, enchantress elaenjoy...@gmail.comwrote: It says K days if you keep heap the order of values gets disturbed. How are last k values accessed then? On Sunday, 15 July 2012 12:46:02 UTC+5:30, adarsh kumar wrote: Min or max heap accordingly. This will do the job in O(log n) time. On Sun, Jul 15, 2012 at 1:25 AM, Navin Kumar algorithm.i...@gmail.comwrote: A set of integer values are being received (1 per day). Store these values and at any given time, retrieve the min and max value over the last k days. What data structures would you use for storing and retrieving ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/* *msg/algogeeks/-/2AhV1Xn3jD8Jhttps://groups.google.com/d/msg/algogeeks/-/2AhV1Xn3jD8J . To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscribe@** googlegroups.com algogeeks%2bunsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/** group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/peWhqjKLIH8J. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- best wishes!! Vaibhav -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Re: Finding the repeated element
Could u please tell me the way to find number repeated odd number of time using X-oR..?? On Sunday, 27 November 2011 00:49:59 UTC+5:30, Gene wrote: Isn't this overkill? If you're already using a set, just check the set before you insert each new element, and you'll discover the duplicates: S = empty while i = input item existss if i in S output i has a duplicate; insert i in S end XOR is generally useful only for detecting a single item that's included in a list an odd number of times rather than an even number of times. On Nov 24, 3:56 pm, Ankur Garg ankurga...@gmail.com wrote: ^^+1..how matrix formed ?? But as Gene said we can use a set to store all the unique elements Now we xor all the set elements and then xor them with the elements of the array . This wud give us the repeating element as all the elements coming once will be 0(xored twice) and repeating element wud be xored twice . To code it as follows int FindSingle(int a[],int n){ setints; s.insert(a,a+n); setint::iterator it; it = s.begin(); int XOR= *it; it++; while(it!=s.end()){ XOR =XOR^*it; it++;} for(int i=0;in;i++) XOR=XOR^a[i]; return XOR; } On Fri, Nov 25, 2011 at 1:03 AM, kumar raja rajkumar.cs...@gmail.com wrote: @Anup: Atleast u tell me how the M has formed??? On 24 November 2011 11:21, Anup Ghatage ghat...@gmail.com wrote: @kunzmilan Nice idea, how do you decide the row-size or column-size of the matrix? On Thu, Nov 24, 2011 at 8:00 PM, kumar raja rajkumar.cs...@gmail.com wrote: @kunzmilan : Can u please maintain the clarity ?? How did u find the M if the list is 4 2 8 9 5 1 9 how M looks like ?? please elaborate it... On 24 November 2011 06:15, kunzmize an kunzmi...@atlas.cz wrote: On 24 lis, 09:09, kumar raja rajkumar.cs...@gmail.com wrote: @kunzmilan : i did not get u, once explain with example... On 23 November 2011 23:47, kunzmilan kunzmi...@atlas.cz wrote: Matrix M 0 1 0 0 1 0 1 0 0 multiplied with M(T) 0 0 1 1 1 0 0 0 0 gives 1 0 0 0 2 0 0 0 0. On its diagonal are numbers of repeated elements. kunzmilan On 24 lis, 07:02, kumar raja rajkumar.cs...@gmail.com wrote: In the given array all the elements occur single time except one element which occurs 2 times find it in O(n) time and O(1) space. e.g. 2 3 4 9 3 7 output :3 If such a solution exist can we extend the logic to find All the repeated elements in an array in O(n) time and O(1) space -- Regards Kumar Raja M.Tech(SIT) IIT Kharagpur, 10it60...@iitkgp.ac.in Write the list in the form of a matrix M, e.g. 0 1 0 0... 0 0 1 0... 0 0 0 1... ..etc., and its quadratic form M(T)M shows, how many times each element repeats. kunzmilan -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Kumar Raja M.Tech(SIT) IIT Kharagpur, 10it60...@iitkgp.ac.in -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Kumar Raja M.Tech(SIT) IIT Kharagpur, 10it60...@iitkgp.ac.in -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Anup Ghatage -- 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Regards Kumar Raja M.Tech(SIT) IIT Kharagpur, 10it60...@iitkgp.ac.in -- 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] Re: microsoft
double round(double num) { return (int)(num+0.5) } will it work all the time? .. didnt get itcan anyone explain it.thnx in advance. On Friday, 26 August 2011 21:58:05 UTC+5:30, rahul sharma wrote: hi guys...microsoft is coming to our campus..plz nyone tell their recruitment procedure..n give me their previous xams question if nyone has...but please tell me their selection procedure n roundscuming after 2 days.plz reply soon.n tell me the subjects to crack microsoft.nyon having info reply fast plz.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/mWeduVanassJ. 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 options, visit this group at http://groups.google.com/group/algogeeks?hl=en.