Re: [algogeeks] Directi Interview Ques
Here you have to first sort both the arrays A and B and merge both the arrays to form the sorted array C -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
[algogeeks] Directi question
Given an array A and the elements stored in an array denotes how much jump an element can make from that array position. For example there is an array A = {4 0 0 3 6 5 4 7 1 0 1 2} Now Ist element which is 4 can make a jump to element 0, 0, 3 and 6. You are stuck if you end up at 0. You have to output the minimum number of jumps that can be made from starting position to end position of an array. -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
Re: [algogeeks] Re: Most compatible people
This is the simple pattern finding problem in which we have to find the most frequent patterns of persons that listens/vote for the same band. Here we can apply the frequent pattern algorithm like FP Tree or Apriori algorithm. Link for the tutorial of FP tree is given below fptree.pdfhttps://docs.google.com/viewer?a=vq=cache:VMwvU2NRwBQJ:www.cis.hut.fi/Opinnot/T-61.6020/2008/fptree.pdf+hl=engl=inpid=blsrcid=ADGEESjlMAI_es1OZC5jGJBJgWzSJ6Xy4yWDlsgZUYCvd9EWcSpnZSf_u_PbGU_zA-9Bx4r2bDq6ChcDCcay5gDEDqStEiu6IheRE3sP9cTPv32GqZ5Xgnm2qoiqmww2tLtk2DS4gWYtsig=AHIEtbToblogHyYVe2nzZpWiwK1QzCjHsQpli=1 Here we have to first convert the choices of the particular person as a hashmapstring,setstring, the key here is the band and the set of strings contains the name of persons who voted for the band. Next step is to create the FP tree from the given set of people for particular band and create the FP tree as per given in the tutorial and find the frequent patterns. -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
Re: [algogeeks] Re: Write a C program to reconstruct a BST from a given array of preorder traversal.
There is no need to use any other data structure or sort the array one can directly construct the BST from a given array by taking one element at a time from the beginning and inserting into a BST. -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
Re: [algogeeks] adobe
Using Two Mallocs : int *data; int **arr; data = malloc(sizeof(int) * nrows * ncols ); arr = malloc(sizeof(int*) * nrows); for ( int i = 0; i nrows; i++) { arr[i] = data[ i * ncols ]; } -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
Re: [algogeeks] trie display
Apply DFS in the trie -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
Re: [algogeeks] Re: Question asked in Amazon Online Test
*Using Stack : * j = 0; for ( int i = 0; i prefix.len(); i++ ) { if ( isOperator(prefix[i]) ) stk.push(prefix[i]); else { postfix[j] = prefix[i]; j++; while ( !stk.empty() stk.top == '#' ) { stk.pop(); postfix[j] = stk.top(); j++; stk.pop(); } stk.push('#'); } } -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
Re: [algogeeks] Find the Max from each sub-array of size k
To do this question in O(n) time follow the post Segment trees in this post of topcoder http://community.topcoder.com/tc?module=Staticd1=tutorialsd2=lowestCommonAncestor Here in this given algorithm preprocessing time in O(n) and query time is O(log n). -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
Re: [algogeeks] Microsoft Interview Question
void make_group( int a[], int size) { int j = 0; for ( int i = 0; i size; i++ ) { if ( a[i] 0 ) { swap(a[i],a[j]); j++; } } } -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
Re: [algogeeks] [amazon]: dutch national flag algorithm
int low,mid,high; low = mid = 0; high = (int)(sizeof(arr)/sizeof(arr[0]))-1; /* According to Dutch national flag problem there are three types of quantities in an array and we have to combine these elements together but in a certain order Let the elements in the array are in the form 0,1,2 then these elements in an array should appear in order 0 then 1 then 2 ( low to middle-1 ) - elements having 0 as a number (middle to high-1 ) - 1 as a number ( high to arr - size) - 2 as a number / n = high; for ( int i = 0; i = n; i++ ) { if ( arr[mid] == 0 ) { swap(arr[low],arr[mid]); low++; mid++; } else if ( arr[mid] == 2 ) { swap(arr[mid],arr[high]); high--; } else { mid++; } } -- 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] [amazon]: dutch national flag algorithm
sorry for the above post , there was careless mistake of mine. The code will be [code] int low,mid,high; low = mid = 0; high = (int)(sizeof(arr)/sizeof(arr[0]))-1; /* According to Dutch national flag problem there are three types of quantities in an array and we have to combine these elements together but in a certain order Let the elements in the array are in the form 0,1,2 then these elements in an array should appear in order 0 then 1 then 2 ( low to middle-1 ) - elements having 0 as a number (middle to high-1 ) - 1 as a number ( high to arr - size) - 2 as a number / n = high; while ( mid = high ) { if ( arr[mid] == 0 ) { swap(arr[low],arr[mid]); low++; mid++; } else if ( arr[mid] == 2 ) { swap(arr[mid],arr[high]); high--; } else { mid++; } } [/code] -- 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] Amazon : Find popular cost
Here, we can use hashmap and use an extra variable max_till_now that will keep track of maximum element occured to us till now while updating. Time complexity of solution will be O(n) max_till_now = 0; for ( int i = 0; i arr.size(); i++ ) { hashmap[arr[i]] += 1; if ( hashmap[arr[i]] max_till_now ) max_till_now = hashmap[arr[i]]; } print(max_till_now); -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) *--* sapraaks...@gmail.com akshatsapr...@gmail.com rit20009008@ rit20009...@gmail.comiiita.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.
Re: [algogeeks] Find the element in Array
Solution: arr[n],sum = 0; for ( int i = 0 ; i n; i++ ) { sum ^= arr[i]; } print sum; // required number -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) -- sapraaks...@gmail.com akshatsapr...@gmail.com rit2009...@iiita.ac.in sapraaks...@facebook.com -- 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] Amazon - Interview Qn
I have provided you the solution and I think you are experienced enough to make the solution yourself but I can provide you a Pseudocode. //Solution for Doubly linked list Inverse(node *start, node *end) { print(end); } print(node *start,node *end) { do { print(end-data); end = end-next; } while ( end != start ) } call the functions two times inverse(0th node,n-1th node); inverse(nth node, list.size()th node); -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) -- sapraaks...@gmail.com akshatsapr...@gmail.com rit2009...@iiita.ac.in sapraaks...@facebook.com -- 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] confusion
Array of Pointers : By Array of Pointers we mean that there is an array that contains the pointers at different index which points to some value in the memory. Example:- int *arr[10] In this array arr[0],arr[1]arr[9] is a pointer that points to some value in a memory. Pointer to array : By Pointer to array we means that there is a pointer that is defined to point to some index in an array. Example:- There is some array arr and we define a pointer a; int *a = arr; then this points to value arr[0]; and if int *a = arr+9; then this points to value arr[9]; -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) -- sapraaks...@gmail.com akshatsapr...@gmail.com rit2009...@iiita.ac.in sapraaks...@facebook.com -- 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: Adding Two no without using any operator...??
can you please tell me how is this working main() { int a=4,b=6; printf(\n%d\n,printf(%*s%*s,a,,b,)); } -- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- 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. -- Akshat Sapra Under Graduation(B.Tech) IIIT-Allahabad(Amethi Campus) -- sapraaks...@gmail.com akshatsapr...@gmail.com rit2009...@iiita.ac.in sapraaks...@facebook.com -- 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.