Re: [algogeeks] Find longest consecutive subsequence

2014-03-16 Thread Ankit Sambyal
Use bitwise hashmap. On Thu, Jan 30, 2014 at 8:46 PM, Don dondod...@gmail.com wrote: No. If you start at any number in a sequence it will find the entire sequence. There is no need to start again at some other number in that sequence. Don On Wednesday, January 29, 2014 12:19:21 AM

Re: [algogeeks] kth smallest element in 2 sorted arrays

2013-06-16 Thread Ankit Sambyal
Maintain the invaraint : i + j = k -1 if B[j-1] A[i] B[j], then A[i] must be the kth smallest else if A[i-1] B[j] A[i], then B[j] must be the kth smallest If the above conditions are not satisfied, subdivide the arrays. On Thu, Jun 13, 2013 at 1:41 PM, sourabh jain wsour...@gmail.com

[algogeeks] UTF-8 encoding

2013-06-09 Thread Ankit Sambyal
Lets suppose there is a UTF8 encoding scheme. You have to check if a string is valid UTF8 or not. Just read the below given description. UTF-8 is a variable-length encoding of letters or runes. If the most significant bit of the first byte is 0, the letter is 1 byte long. Otherwise, its length is

Re: [algogeeks] least common ancestore bst

2013-06-05 Thread Ankit Sambyal
struct node { int data; struct node* left; struct node* right; }; struct node* newNode(int ); /* Function to find least comman ancestor of n1 and n2 */ int leastCommanAncestor(struct node* root, int n1, int n2) { /* If we have reached a leaf node then LCA doesn't exist If

Re: [algogeeks] Re: Highest reminder

2013-06-05 Thread Ankit Sambyal
: = 9 * 1 + 8 Number/2 = 8.5 So, its neither floor(n/2) +- 1, nor ceil(n/2) +- 1 On Wed, May 29, 2013 at 2:19 PM, Ankit Sambyal ankitsam...@gmail.com wrote: Hi Nikhil, Highest remainder can't be floor(n/2) - 1. If n = 11, highest remainder would be 5 when it is divided by 6

Re: [algogeeks] Re: Highest reminder

2013-05-29 Thread Ankit Sambyal
Hi Nikhil, Highest remainder can't be floor(n/2) - 1. If n = 11, highest remainder would be 5 when it is divided by 6, but your formula gives 4. On Mon, May 27, 2013 at 8:16 PM, Nikhil Kumar niksingha...@gmail.comwrote: Since we need to divide so the quotient should be at least 1, and we need

Re: [algogeeks] Array of intergers with repeating elements

2013-05-12 Thread Ankit Sambyal
Are these n+1 elements range from 1 to n+1 ? On Wed, May 8, 2013 at 12:02 AM, MAC macatad...@gmail.com wrote: I was asked this in recent amazon onsite interview and asked o write code Given an Array of integers . N elements occur k times and one element occurs b times, in other words

[algogeeks] MS question

2011-08-14 Thread ankit sambyal
You have to make a package library which will do the calculation of (a^b)mod(c), where a, b, c are very large size of 1 digits. (^- power). Design a data structure for the numbers' storage and suggest what functions will you be providing to user with them. Also mention the advantages of using

Re: [algogeeks] MS question

2011-08-14 Thread ankit sambyal
@sagar : What is the best answer for this question ?? -- 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

Re: [algogeeks] Remove spaces

2011-08-12 Thread ankit sambyal
void delExtraSpaces (char *Str) { int Pntr = 0; int Dest = 0; int flag=0; while (Str [Pntr]) { if (Str [Pntr] != ' ') { Str [Dest++] = Str [Pntr]; flag=0; } else if(Str[Ptr]==' ' flag==1) Str [Dest++] = Str [Pntr]; else flag=1; Pntr++; } Str [Pntr] = '/0'; } --

Re: [algogeeks] Remove spaces

2011-08-12 Thread ankit sambyal
Guys sorry for posting the buggy code . Here is the working code : void delExtraSpaces (char Str[]) { int Pntr = 0; int Dest = 0; int flag=0; while (Str[Pntr]!='\0') { if (Str[Pntr] != ' ') { Str[Dest++] = Str[Pntr]; flag=0; } else if(Str[Pntr]==' ' flag==0) { Str[Dest++] =

Re: [algogeeks] Re: Amazon question.

2011-08-10 Thread ankit sambyal
@kunal, anuj : step 2 of my algo takes O(n^2). So how can the TC be O(nlogn) -- 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

Re: [algogeeks] Problems on Linked List

2011-08-10 Thread ankit sambyal
Ques 1: Let l1 and l2 be the 2 lists. Step 1 : Reverse l1 O(n) Step 2 : Compare l1 and l2 by comparing each node and traversing ahead.--O(n) Step 3: Reverse l1 -O(n) Ques 2: Let cur be the node of the linked list which is to be

Re: [algogeeks] problem regarding output??

2011-08-09 Thread ankit sambyal
its because void pointer is incremented by 1, when we do k++ whereas integer pointer is incremented by 4, when we do j++ -- 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

Re: [algogeeks] problem regarding output??

2011-08-09 Thread ankit sambyal
The typecasting tells the compiler that the void pointer is now pointing to an integer and when we use this pointer to access the integer it takes value from 4 bytes. But when we try to increment that pointer, it will point to the next byte. Try taking k as pointer to double instead of void, u

[algogeeks] MS question

2011-08-09 Thread ankit sambyal
Given an array of characters, change the array to something as shown in the following example. Given : ddbbccae O/P : 2d4a2b2c1a1e Do it in the most efficient manner both in terms of time and space ... -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] MS question

2011-08-09 Thread ankit sambyal
@shady : I think there is a catch in that approach. Plz post ur 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

Re: [algogeeks] MS question

2011-08-09 Thread ankit sambyal
@raghavan: ur approach uses O(n) space -- 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

Re: [algogeeks] MS question

2011-08-09 Thread ankit sambyal
@sagar: for abcd, ur pgm gives abcd. I was trying a pgm which gives 1a1b1c1d. But now i think this problem is wrong, because in this case it exceeds the size of the array if we try to o/p as 1a1b1c1d. Hence we require a new array for it. -- You received this message because you are subscribed to

Re: [algogeeks] MS question

2011-08-09 Thread ankit sambyal
ya got it now. I misunderstood the question -- 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.

Re: [algogeeks] Amazon question.

2011-08-09 Thread ankit sambyal
1. Square each element of the array and then sort it---O(nlogn) 2. for(i=0;i(size-3);i++) { j=i+1; k=size-1; while(jk) { if(a[[i] + a[j] == a[k]) printf(\n%d %d %d,sqrt(a[i]),sqrt(a[j]),sqrt(a[k])); else if(a[i] + a[j] a[k]) j++;

Re: [algogeeks] mcq

2011-08-08 Thread ankit sambyal
C -- 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

[algogeeks] Amazon Question

2011-08-08 Thread ankit sambyal
Plz give the answers ... 1. In a binary max heap containing n numbers, the smallest element can be found in time ?? 2. The number of total nodes in a complete balanced binary tree with n levels is, a)3^n + 1 b)2^(n+1) - 1 c) 2^n + 1 d) none of above 3. In a country where everyone wants

Re: [algogeeks] Re: amazon question

2011-08-08 Thread ankit sambyal
the order of printfs depend on the scheduling algorithms which OS is following and can't be predicted -- 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

Re: [algogeeks] amazon question

2011-08-08 Thread ankit sambyal
@aditi : the ans is 3. Why do u think there is no definite ans ? -- 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

Re: [algogeeks] Doubts

2011-08-08 Thread ankit sambyal
@aditya : can u explain how u got c part as the answer for question 2 -- 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

Re: [algogeeks] MS test

2011-08-07 Thread ankit sambyal
@programming love : 6.5 can be represented accurately in binary -- 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

Re: [algogeeks] MS test

2011-08-07 Thread ankit sambyal
@programming love : 0.1 can't be represented accurately in binary. If u try to convert it into binary, it will not terminate. Try it !! But 6.5 can be converted. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] Sum from array

2011-08-07 Thread ankit sambyal
@swetha: This problem can't be solved in O(n) -- 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

Re: [algogeeks] MICROSOFT INTERVIEW QUESTIONS faced by my frenz nd me

2011-08-07 Thread ankit sambyal
Can anybdy explain the following questions : (5) Find the output int arr[2][3]={{1,2,3},{4,5,6}}; int (*ptr)[3]=a[0]; printf((%d,%d),(*ptr)[1],(*ptr)[2]); ptr+=1; printf((%d,%d),(*ptr)[1],(*ptr)[2]); Will this program compile properly or will end in segmentation fault ?? (9) Given a inorder

Re: [algogeeks] amazon

2011-08-07 Thread ankit sambyal
bubble sort -- 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

Re: [algogeeks] Probability Puzzle

2011-08-07 Thread ankit sambyal
17/80 On Sun, Aug 7, 2011 at 10:34 AM, Algo Lover algolear...@gmail.com wrote: A bag contains 5 coins. Four of them are fair and one has heads on both sides. You randomly pulled one coin from the bag and tossed it 5 times, heads turned up all five times. What is the probability that you

Re: [algogeeks] MICROSOFT INTERVIEW QUESTIONS faced by my frenz nd me

2011-08-07 Thread ankit sambyal
@coder : Cud u plz explain the approach for question 9 ?? -- 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

Re: [algogeeks] Re: probablity

2011-08-07 Thread ankit sambyal
the answer is 1/2 -- 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

Re: [algogeeks] Re: amazon online test format

2011-08-06 Thread ankit sambyal
Is there any time limit for the questions in amazon online test ? I mean shud we write efficient code or shud we just make our pgm rum ? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] MS test

2011-08-06 Thread ankit sambyal
4. a 6 b -- 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

Re: [algogeeks] MS test

2011-08-06 Thread ankit sambyal
the code given in question 5 should not terminate because of the condition of the for loop -- 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

Re: [algogeeks] MS test

2011-08-06 Thread ankit sambyal
ya the answer for 1st one is b -- 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] MS test

2011-08-06 Thread ankit sambyal
@sukran: 40%of work i.e. 120 sec of work is sequential and can't be distributed among multiple processors. Since we hv to complete the work in 150 sec, so we r left with 30 sec. Remaining 60% work=180sec. 180/30=6 So we require 5 additional processors -- You received this message because you

Re: [algogeeks] MS test

2011-08-06 Thread ankit sambyal
@neha: Cud u explain how r u getting d option for ques 4 ?? -- 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

Re: [algogeeks] address calculation

2011-08-06 Thread ankit sambyal
A[3][4]= 1049 B[3][4]= 2196 -- 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] address calculation

2011-08-06 Thread ankit sambyal
@aditi: explain ur answer.. How u got it ? -- 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.

Re: [algogeeks] Header Files

2011-08-06 Thread ankit sambyal
yeah Siddarath's point is correct that they do hv preprocessors to prevent multiple includes. And they would be using #ifndef instead of #pragma as it is not a documented standard -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread ankit sambyal
First traverse the string and hash each word into a hash table if it is not present in the hash table. Then again traverse the string and hash each word. If the word is not present in the hash table, output it to the console. -- You received this message because you are subscribed to the Google

Re: [algogeeks] Re: remove duplicate words in a string

2011-08-05 Thread ankit sambyal
If no extra memory is allowed, then I think we can't do better than O(n^2), which is pretty straight forward. -- 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

Re: [algogeeks] Structure Q

2011-08-05 Thread ankit sambyal
error because head is a pointer to the structure, hence head.x gives an error -- 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

Re: [algogeeks] My senior's Interview Experience at Microsoft who got selected and offered a 16lacks package

2011-08-04 Thread ankit sambyal
Can anybody explain following questions from the above interview: Question: Output: int main() { char *str = “junk”; scanf (“%[A telephonic girl]”, str); printf (“%s\n”, str); return 0; } Question : Data Structure that can be useful for the calculation like ab

Re: [algogeeks] Normal Form

2011-08-04 Thread ankit sambyal
BCNF -- 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

[algogeeks] OS question

2011-08-04 Thread ankit sambyal
What happens when a thread calls exec ?? What happens to the other threads of the same process ?? -- 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,

Re: [algogeeks] OS question

2011-08-04 Thread ankit sambyal
@Dipankar: But all the threads of a process share code and data section. So, how is it possible that they are not affected ??? -- 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

Re: [algogeeks] OS question

2011-08-04 Thread ankit sambyal
Thnks Azhar :) got the point -- 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] Re: Puzzle

2011-08-04 Thread ankit sambyal
@aditi:Thats a non uniform rope. The 1st half may burn faster than 2nd half. btw Priyanka's solution is correct. -- 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

[algogeeks] Least Common Ancestor in an n ary tree

2011-08-04 Thread ankit sambyal
Find LCA in n ary tree ? -- 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,

Re: [algogeeks] Complexity Help..

2011-08-03 Thread ankit sambyal
@Aanchal : My mistake... Its complexity can't be O(n^2) -- 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] Amazon Question

2011-08-03 Thread ankit sambyal
Given two lists write a function which returns a list which is the intersection of the two lists.the original lists should remain same. (Intersection - if first list is say,1,20 3,45 and second list is 3,24 ,45,90,68 then intersection should be 3,45 ) -- You received this message because you are

Re: [algogeeks] C question.. increment decrement operator..

2011-08-03 Thread ankit sambyal
Its compiler dependent. Acc. to the C standard an object's stored value can be modified only once in an expression. -- 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

Re: [algogeeks] Amazon Question

2011-08-03 Thread ankit sambyal
ya, I also can't think anything better than O(m*n) -- 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

Re: [algogeeks] MS [Written Question]

2011-08-03 Thread ankit sambyal
For question 1: Take 2 arrays prod_before[N] and prod_after[N] which hold product of elements before and after i respectively For i=1 to N-1 calculate prod_before[i] For i=N-2 to 0 calculate prod_after[i] prod_before[0]=prod_after[N-1]=1 For i=0 to N-1 prod[i]=prod_before[i] *

Re: [algogeeks] MS [Written Question]

2011-08-03 Thread ankit sambyal
For question 2: 1. check with empty string. 2. check with a string which is in the file 3. check with a string which is not in the file 4.check with a string which has a different case as that in the file. eg. if the file contains structure and does not contain Structure, check find and replace

Re: [algogeeks] MS [Written Question]

2011-08-03 Thread ankit sambyal
Anybody having any of question 3 ??? -- 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

Re: [algogeeks] Re: MS [Written Question]

2011-08-03 Thread ankit sambyal
@Poised: Whats the answer of : double round(double num) { return (int)(num+0.5) } will it work all the time? I think the answer should be Yes. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Amazon Aptitude questions

2011-08-03 Thread ankit sambyal
1.*What is the wrong in this program *main() { char *p,*q; p=(char *)malloc(25); q=(char*) malloc(25); strcpy(p,amazon ); strcpy(q,hyd); strcat(p,q); printf(%s,p); } 2.*write prefix and post fix notation for (a+b)*c-(d+e)^(f-g) 3.**what is valid in cpp char *cp; const char *cpp; 1) cpp=cp; 2)

Re: [algogeeks] Re: Minimum cuts required so that each sub string is a palindrome

2011-08-03 Thread ankit sambyal
@amit: can u supply the code for ur approach ?? -- 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

Re: [algogeeks] Re: Amazon Aptitude questions

2011-08-03 Thread ankit sambyal
for question 3: cpp=cp is the correct answer. Can anybody explain ? -- 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

Re: [algogeeks] Re: Minimum cuts required so that each sub string is a palindrome

2011-08-03 Thread ankit sambyal
thnks amit.. -- 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

Re: [algogeeks] Amazon Question

2011-08-02 Thread ankit sambyal
@payel : Is it sub-sequence or sub-array ?? A sub-sequence may not be continuous but a sub-array must be continuous. eg : What wud be the answer for- 100110 ?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

[algogeeks] Minimum cuts required so that each sub string is a palindrome

2011-08-02 Thread ankit sambyal
You are given a large string. You need to cut the string into chunks such that each substring that you get is a palindrome. Remember that each 1 length string is always a palindrome. You need to find the minimum number of cuts that you need to make such that each substring is a palindrome. --

Re: [algogeeks] Complexity Help..

2011-08-02 Thread ankit sambyal
@Ravinder : Its not a DP problem.. If it was, where are the sub problems reused or in other words, where is memoization ?? @Anchal : Its complexity is O(n^2). Look at the following segment in ur code : for(int i=index[n];isz;i++) { index[n+1]=i;

Re: [algogeeks] Max subarray of no 2 adjacent elements

2011-08-01 Thread ankit sambyal
just use the following recurrence relation : let arr[] be the array of integers and take an array a[] a[i]=max(a[i-2], a]i-1], a[i-2]+arr[i]); a[0]=arr[0]; a[1]=max(arr[0],arr[1]); a[N-1] contains the final answer @abhishek : the output for {3,5,7,10} should be 5+10=15 and not 13 as pointed by

Re: [algogeeks] Sort IT

2011-08-01 Thread ankit sambyal
@raja : The range is 1-N^2 and not 1-N. Had it been 1-N , we could have easily sorted the array in O(N) time using bit map. -- 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

Re: [algogeeks] Re: C doubt

2011-07-31 Thread ankit sambyal
yup its correct... -- 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

Re: [algogeeks] Write C code to check if an integer is a power of 2 or not in a single line?

2011-07-30 Thread ankit sambyal
If x is the number which is to be checked, if (x !(x (x-1)) == 0) then power of 2 -- 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

Re: [algogeeks] Programming Puzzle!!!!!!!

2011-07-29 Thread ankit sambyal
Let S be the exact amount for which minimum coins are to found. And denom[] be the array which contains different denominations. Let N be the size of the denom[] array. Algo: 1. int memo[S] 2. initialize all its elements to infinite 3.for i=1 to S for j=0 to N-1 if(denom[j] i

Re: [algogeeks] Programming Puzzle!!!!!!!

2011-07-29 Thread ankit sambyal
I have used dynamic programing to solve the problem. I have used memo[] array to memoize the value of previous state. You should take an example and try to work it out using the algo... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post

Re: [algogeeks] Programming Puzzle!!!!!!!

2011-07-29 Thread ankit sambyal
It means a very large value, can be the max value that an integer can hold -- 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

Re: [algogeeks] Programming Puzzle!!!!!!!

2011-07-29 Thread ankit sambyal
@aman: My mistake. set* memo[0]=0* The revised algo is : Algo: 1. int memo[S] 2. initialize all its elements to infinite. * 3.memo[0]=0* 4.for i=1 to S for j=0 to N-1 if(denom[j] imemo[i-denom[j]] +1 memo[i]) memo[i]=memo[i-denom[j]] +1 5. return memo[S] --

Re: [algogeeks]

2011-07-29 Thread ankit sambyal
@anika: Here is the iterative code: void iter_mirror(Node *root) { if(root==NULL) return; Node *stack[100]; Node *temp,*temp1; int top=-1; stack[++top]=root; while(top!=-1) { temp=stack[top]; temp1=temp-left; temp-left=temp-right;

Re: [algogeeks] Re: binary search tree question!!!!

2011-07-29 Thread ankit sambyal
Here the required program : void findkthSmallest(Node *root,int k) { Node *stack[100]; int top=-1,count=0; Node *temp; stack[++top]=root; /*First we will find the minimum node*/ temp=root; while(temp-left != NULL) { stack[++top]=temp-left;

Re: [algogeeks] DE Shaw - Data Structure Section Qn

2011-07-28 Thread ankit sambyal
In the question it is specified that the data structure should have a worst case time complexity of O(N) -- 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

Re: [algogeeks] Puzzle!!!!!

2011-07-28 Thread ankit sambyal
use the following recursive equation : S{i]=max(S[i-2]+a[i],S[i-1]) S[0]=a[0] S[1]=max(a[0],a[1]) S[size-1]is the required answer -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Puzzle!!!!!

2011-07-28 Thread ankit sambyal
1. Make an array S equal to the length of the given array where S[0] = a[0] and S[1] = max(a[0],a[1]) 2. for i:2 to n-1 S[i] = max(S[i-2]+a[i], S[i-1]) 3. return S[n-1] -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] direct i

2011-07-27 Thread ankit sambyal
O(n^2) algo is trivial. Can anybody think of a better approach ??? -- 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

Re: [algogeeks] Re: Fwd: SORTING ARRAYS

2011-07-27 Thread ankit sambyal
Following is the working code :Time complexity : O(n^2) Space complexity : O(1) void swap(int *a,int *b) { int temp; temp=*a; *a=*b; *b=temp; } /*num is the number which is searched in the array arr[]. index is the index in the array arr[] by which the searched number is to

Re: [algogeeks] Re: Fwd: SORTING ARRAYS

2011-07-27 Thread ankit sambyal
@anand: How are you building minheap ?? Comparison of same array elements is not allowed ! -- 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,

Re: [algogeeks] Least Common Ancestor

2011-07-27 Thread ankit sambyal
First make an iterative DFS function which stores node pointers on the stack instead of node values and break as soon as the node value of the node pointer on the top of the stack reaches a specified value. void iterative_dfs(Node *root,int n1); Let n1 and n2 be the values whose LCA is to be

Re: [algogeeks] DE Shaw - Data Structure Section Qn

2011-07-27 Thread ankit sambyal
d) Hast table with bucket, made up of linked list, where linked list have no ordering. -- 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

Re: [algogeeks] Array question

2011-07-26 Thread ankit sambyal
The O/P of ur example should be 2,2,1,1,1,-1,-1 or am I getting it wrong ?? -- 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

Re: [algogeeks] Re: Array question

2011-07-26 Thread ankit sambyal
@Akshata : Plz explain ur algo... Its not clear. Like in the first iteration, else l = stk.top; is getting executed. but stack is empty, so how r u assigning value to l -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

Re: [algogeeks] Amazon Question

2011-07-26 Thread ankit sambyal
@Swetha :Number of possible sub strings of a string of length n is of the order of n^2. So, there can,t be a better solution than O(n^2) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Competetive C-Question

2011-07-26 Thread ankit sambyal
D) S1 and S2 both are true S2 is true because return a[i+2]-3; takes more time than return t2-3; -- 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,

Re: [algogeeks] Re: Amazon Question

2011-07-26 Thread ankit sambyal
@vivin : Suffix trees are memory intensive.. This problem can be solved just by running 2 nested loops in O(1) space and O(n^2) time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread ankit sambyal
@vivin : Your algo seems to be wrong. Plz take an example and explain. I may hv misunderstood u .. -- 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

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
int getFirstIndexInLex(char arr[],int size) { int minindex=0,i; for(i=1;isize;i++) { if(arr[i] arr[minindex]) minindex=i; else if(arr[i]==arr[minindex]) minindex=checkmin(arr,size,minindex,i); } return minindex; } int checkmin(char

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
There is a mistake in my code: In the function int checkmin(char arr[],int size,int i,int j) after the while loop in the line if(k==0) It shud be : if(k==size) instead of if(k==0) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
@coder: my mistake. There is a typo in my code. the condition is : while(arr[i]==arr[j] ksize) -- 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,

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
@coder : No, my solution gives the correct answer. Check it out again !! -- 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

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
@coder :Got my mistake. There is a slight change in the checkmin function. Actually I was returning the modified value of i and j. Following is the correct code : #includeiostream using namespace std; int checkmin(char arr[],int size,int i,int j) { int k=0,*m=i,n=j*; while(arr[i]==arr[j]

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread ankit sambyal
@rajeev:ur algo does not give the correct answer. -- 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

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread ankit sambyal
@bharath :I think array C is not the resultant array. Take an example and explain -- 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

Re: [algogeeks] Question

2011-07-25 Thread ankit sambyal
Incomplete Information -- 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,

  1   2   >