Re: [algogeeks] find out all pairs of numbers a,b such that a^2+b^2 = N

2013-02-13 Thread Guneesh Paul Singh
Replace all elements of array by its square.and sort it Now question is to find two nos in the array such that their sum is N. For this take two pointers min and max Initialize min to 0 and max to n-1(n-size of array) 1.find the sum a[min]+a[max] 2.if sumN max=max-1 if sumN min=min+1 if sum==N we

Re: [algogeeks] Amazon interview Question

2013-02-05 Thread Guneesh Paul Singh
in above algo primary index is no of times that value is repeated till now -- 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

Re: [algogeeks] Amazon interview Question

2013-02-04 Thread Guneesh Paul Singh
I can think of an o(n^2) algo for 2n question Make a heap formed acctoring to two indexes 1.Primary -value 2.Secondary - index Now for each new incoming value first search in head if exist inc its index else make a new node -- You received this message because you are subscribed to the Google

Re: [algogeeks] Modified String Searching

2013-01-27 Thread Guneesh Paul Singh
the difference array for range 4-7 is [1,1,0,1] it is not a sol [2,2,1,1](index no 7) -[1,1,1,0](index of 3)

Re: [algogeeks] maximum disjoint sets

2013-01-24 Thread Guneesh Paul Singh
Make a directed graph out of the set of edges where an edge indicates the the sets are not disjoint . Now question is to remove min no of sets so that no sets exist. for this apply the following algo 1.Select the edge with of min degree(nonzero) delete its parent. 2.repeat the step 1 on the

Re: [algogeeks] Modified String Searching

2013-01-22 Thread Guneesh Paul Singh
@Sairam i m 100 % sure about the correctness of the algo.i have proven it with test case.. Only way u can prove it wrong is to give a counter case not by intutive feeling. if u find the diffence of count arrays for two indexes i and j then it indicates the count of the string starting from i and

Re: [algogeeks] MS Question

2013-01-20 Thread Guneesh Paul Singh
not possible unless u use augmented bst..which itself takes o(n) to built --

Re: [algogeeks] Modified String Searching

2013-01-20 Thread Guneesh Paul Singh
This is a test This is a programming test This is a programming test in any language 1 1 1 122 2 2 233 3 3 3 3 33(count of this) 0 0 1 111 2 2 222 3 3 3 3 3

Re: [algogeeks] Modified String Searching

2013-01-20 Thread Guneesh Paul Singh
to make it O(n logn) 1.Chose one index O(n) 2.For this index do a bsearch on remaining array to find the postion bsearch can be done as the array is an increasing function(it donotes no of occurrence of each word,so=previous index value) bsearch will be done like this 1.make a new temp array that

Re: [algogeeks] matrix Multiplication

2013-01-19 Thread Guneesh Paul Singh
consider code to find n^k where n is an integer int power() { int ans=1,val=1; while(k) { val=val*n; if(k1)ans=ans*val; k=k1; } return ans; } now if n is is a matrix all you have to do is replace * by matrix multiplication algorithm --

Re: [algogeeks] Modified String Searching

2013-01-19 Thread Guneesh Paul Singh
O(nlogn) algo for each postion in paragraph store the frequency of the given words(from start point to this point) . now in resultant array you need to two indexes that have =1 value in the difference of the frequency of two points. eg hello hello are you hello ,you hello hello are you 1

Re: [algogeeks] matrix Multiplication

2013-01-19 Thread Guneesh Paul Singh
both recursive and iterative codes are O(nlogn) algos.. but memory will be more in recursion.. so we will prefer iteration --

Re: [algogeeks] matrix Multiplication

2013-01-19 Thread Guneesh Paul Singh
@dave thanks for correcting :) --

Re: [algogeeks] Remove duplicates from min-heap.

2012-07-16 Thread Guneesh Paul Singh
yaar i can think of only 2 methods for this 1. O(nlogn) o(n) sol traverse the heap...and hash the elements..if it exist then delete it 2.make another heap but transfering elements from 1st to 2nd heap...if the element is equal to the last inserted element then discard it -- You received

Re: [algogeeks] print spiral

2012-06-15 Thread Guneesh Paul Singh
void spiral(int a[][],int m,int n) { int c=1; -- 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 Question

2012-06-15 Thread Guneesh Paul Singh
void change(int a[],int n) { int i,j; i=0; j=1; while(injn) { if(ji) j=i+1; else if(a[j]0a[i]0) { swap(a,j,i); } else { if(a[j]0) j++; else i++; }

Re: [algogeeks] Re: Power(n^n)

2012-06-11 Thread Guneesh Paul Singh
@abhisheikh read the problem statement again...it says 1000 digits not 1000 value.. -- 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] plz reply quickly

2011-09-23 Thread Guneesh Paul Singh
loop in a link list doesn't necessarily mean a circular link list(d one u hav assumed) eg in this case 1-2-3-4-5-3 there is a loop which in order to detect requires d use of hair tortoise rule -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

Re: [algogeeks] affect of change

2011-08-31 Thread Guneesh Paul Singh
the value of d expression i++ is a integer constant.so u cant assign to a value 20 to it same is d case if u execute (i++)++; On 8/30/11, rahul vatsa vatsa.ra...@gmail.com wrote: @nidhi, if u change the i++ to ++i in D, it will compile, bt off course it will keep on printing 20 in an

Re: [algogeeks] Re: Let's see if U can find the bug...

2011-08-31 Thread Guneesh Paul Singh
@Don Which compiler r u usingi m getting d correct o/p for pow as well On 8/31/11, Don dondod...@gmail.com wrote: pow works with double (floating point) values, not integers, and when you assign the result to an integer, it truncates. You will be better off, both in speed and correctness,