Re: [algogeeks] How will you implement a stack using a priority queue. Push and pop should be in O(1)

2013-05-25 Thread Ankur Khurana
> -- > Rohit Jangid > http://rohitjangid.com > Graduate > Deptt. of Computer Engineering > NSIT, Delhi University, India > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To unsubscribe from this group

Re: [algogeeks] How to implement Longest Increasing Subsequence in O(nlogn) time

2012-03-06 Thread ankur srivastava
@atul: Well yes this might help, thanks :) On Tue, Mar 6, 2012 at 4:24 PM, atul anand wrote: > hope this will help you :- > > http://www.algorithmist.com/index.php/Longest_Increasing_Subsequence.cpp > > On Tue, Mar 6, 2012 at 3:26 PM, ankur wrote: > >> Did any one

[algogeeks] How to implement Longest Increasing Subsequence in O(nlogn) time

2012-03-06 Thread ankur
Did any one implement this in nlogn ?? Reference: http://en.wikipedia.org/wiki/Longest_increasing_subsequence -- 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] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Ankur Garg
ow; > head=ptr; > } > ptr->next->next=follow; > if(follow!=NULL) > follow->next->next=NULL; > } > > @ankur: if odd number of nodes then maybe just ask interviewer how he > wants it to be and try including that case ;) > > > } > > On Mon, Jan 2

Re: [algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Ankur Garg
wat if u have odd no of nodes On Tue, Jan 24, 2012 at 12:00 AM, atul anand wrote: > one simple way would be using stacks. > push node,node->next; > then pop() , and reversing the pointers. > > On Mon, Jan 23, 2012 at 11:46 PM, Ankur Garg wrote: > >> Say LL is &

[algogeeks] MS Question -Reverse a Linked List in size of 2

2012-01-23 Thread Ankur Garg
Say LL is 1->2->3->4->5->6->7->8 Then u need to return 7->8->5->6->3->4->1->2 U cant swap the values U have to rearrange the ptr... -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googleg

[algogeeks] Time Complexity Ques

2012-01-15 Thread Ankur Garg
Hello I was going through this link http://www.geeksforgeeks.org/archives/3187 Wonder what is the time complexity for this..?Can anyone explain > Regards Ankur -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to thi

Re: [algogeeks] Linked list MS Q

2012-01-14 Thread Ankur Garg
XOR Linked Lists On Sat, Jan 14, 2012 at 7:06 PM, Ashish Goel wrote: > design a linked list that has only one pointer per node yet can be > traversed in forward or reverse direction. > > > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006652 > >

Re: [algogeeks] MS Question

2012-01-14 Thread Ankur Garg
@Himanshu Nice idea..that shud do..but how do we code that ? regards Ankur On Sat, Jan 14, 2012 at 2:23 PM, payal gupta wrote: > @himanshu thnx..:) > > Regards, > PAYAL GUPTA, > 3rd YR ,CSE, > NIT-BHOPAL. > > > On Fri, Jan 13, 2012 at 9:42 PM, Himanshu Neema < &g

[algogeeks] MS Question

2012-01-11 Thread Ankur Garg
How to do this Write a function to reverse a UTF-8 encoded string in-place ?? -- 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 alg

Re: [algogeeks] Re: sort 2D array

2012-01-11 Thread Ankur Garg
...(Recursive) Do you think it will be possible this way ? Please correct me in case I got things wrong here regards Ankur On Wed, Jan 11, 2012 at 5:07 PM, atul anand wrote: > i have little doubt in complexity of proposed algo.. > aren't we including complexity of heapifyin

Re: [algogeeks] sort 2D array

2012-01-11 Thread Ankur Garg
If we use K merge I think the time complexity would be nm lognm I think we must try doing in O(m*n) On Wed, Jan 11, 2012 at 1:54 PM, Ankur Garg wrote: > @Shady Rows are already sorted ... > > > On Wed, Jan 11, 2012 at 1:53 PM, shady wrote: > >> ^^ true, sort the rows a

Re: [algogeeks] sort 2D array

2012-01-11 Thread Ankur Garg
@Shady Rows are already sorted ... On Wed, Jan 11, 2012 at 1:53 PM, shady wrote: > ^^ true, sort the rows and then a K-way merge. > > > On Wed, Jan 11, 2012 at 1:00 PM, Sanjay Rajpal wrote: > >> I guess sort the array such that elements are sorted finally in such a >> way that if we print them r

Re: [algogeeks] Re: finding subarray

2012-01-09 Thread Ankur Garg
I think this wont work for cases with negetive nos Ex -2,8,-6 On Tue, Jan 10, 2012 at 6:51 AM, sravanreddy001 wrote: > > solution at this link: > http://ideone.com/ifVIv > > for every position, (iteration) > maitain left, right for the sums, > keep adding elements towards the begenning to left,

Re: [algogeeks] MS Q

2012-01-09 Thread Ankur Garg
Can you give an example Say matrix is 1 1 0 0 1 1 0 0 0 0 1 1 Has it got 3 islands i.e 1-1 be in same row or they can be column wise also i.e. 5 On Tue, Jan 10, 2012 at 7:09 AM, Ashish Goel wrote: > there is a matrix of 1 and 0 > 1 is a island and 0 is water > 1-1 together makes one island

Re: [algogeeks] finding subarray

2012-01-09 Thread Ankur Garg
@Priyanka ...Do the elements of the subarray need to be continuous ..The example considers it continuous but still just for clarity ? On Tue, Jan 10, 2012 at 12:50 AM, surender sanke wrote: > using extra space of O(n) we can do it in O(n^2) > take an array for storing cumulative sums from index i

Re: [algogeeks] Re: check Similar array

2012-01-04 Thread Ankur Garg
sorry it shud be sum of squares and xor and sumof elements I think this shud work Regards Ankur On Wed, Jan 4, 2012 at 9:52 PM, atul anand wrote: > @ Karthikeyan : > > sum of cubes fails:- > > arr1={2,3,0,-3} = 4 > arr2={1,1,1,1} = 4 > > On Wed, Jan 4, 2012 at

Re: [algogeeks] Re: check Similar array

2012-01-04 Thread Ankur Garg
What if we check these 2 conditions XOR and sum of elements and sizeof array same I cudnt find any counter example Regards Ankur On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B wrote: > Hi, > > Consider, arr1={1,2,3} and arr2={-1,-2,-3} > > using sum of squares method sum

Re: [algogeeks] Re: Longest sequence of numbers with atmost diff K

2012-01-02 Thread Ankur Garg
x.back()]-a[i])>k)) index.pop_back(); } For the second part that you said , yes potentially if we use queue.size() we can miss out on continuous part .. Thanks for pointing these out Regards Ankur On Tue, Jan 3, 2012 at 4:06 AM, Ankur Garg wrote: > @Lucifer > > I checked with my code > &g

Re: [algogeeks] Re: Longest sequence of numbers with atmost diff K

2012-01-02 Thread Ankur Garg
would be great .. I am sharing the source codes .cpp file If u find any case thats missing ..please tell me and I will also update in case some case misses out Thanks very much for looking into it :) Thanks and Regards Ankur On Tue, Jan 3, 2012 at 3:26 AM, Lucifer wrote: > @Ankur.. > > A

Re: [algogeeks] Re: Longest sequence of numbers with atmost diff K

2012-01-02 Thread Ankur Garg
I think this can be solved in NlogN using binary search Here is the idea We take a deque which stores the index of the array in increasing order i.e. the index with minimum value is always on the front of the deque Now when a new element comes we check with the front of this deque . If the dif

Re: [algogeeks] [Off-topic] Amdocs Interview Questions

2011-12-28 Thread Ankur Garg
Dude please ask these question on Interviewstreet group.. Your queries will be answered there Kindly adhere to the protocols of this group.. This may be one off thing but it can lead to start of interview queries.So please understand :) On Thu, Dec 29, 2011 at 12:35 AM, Jyoti Malik wrote:

Re: [algogeeks] Re: Frequency Sort Algo

2011-12-25 Thread Ankur Garg
ite 4,4 to array. > > > > for node 2 > > frequency = 3 > > number =2 > > > > write 2,2,2 to the given array... > > > > > > > > On Sat, Dec 24, 2011 at 10:57 PM, Ankur Garg > wrote: > > > how can one do frequency sort

Re: [algogeeks] Re: Frequency Sort Algo

2011-12-25 Thread Ankur Garg
@Atul..your solution is correct and would do the job but its complexity wud be nlogn . Any better way of solving it ? Regards Ankur On Sun, Dec 25, 2011 at 2:10 AM, sravanreddy001 wrote: > any better approach than O(N log N) time? > > maintain a heap of nodes > for each element

[algogeeks] Frequency Sort Algo

2011-12-24 Thread Ankur Garg
how can one do frequency sort . Suppose we have an integer array like 1,2,3,1,2,3,1,1,2,3,4,4,3,5,3 Then 1 is appearing 4 times 2 - 3 3- 5 4-2 5-1 Then if we sort by frequency we shud have this as result 5,4,4,2,2,2,1,1,1,1,3,3,3,3,3 How to do it -- Y

Re: [algogeeks] Re: How to solve this

2011-12-24 Thread Ankur Garg
The thing is ..will it ascertain that the probability is equal I am not sure how ur method guarantees that... May be if you and Dave can explain the algo a bit better that wud be great . regards Ankur On Sat, Dec 24, 2011 at 5:48 AM, Piyush Kansal wrote: > Hey Ankur, > > What is the

[algogeeks] How to solve this

2011-12-23 Thread Ankur Garg
Suggest an algo with which u can find a random node in an infinitely long linked list -- 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] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-21 Thread Ankur Garg
think we can reverse the n-ary tree ,but again my doubt is what will be leaf nodes then in that case , It seems it will be original root , so i was confused . anyway , I will concentrate on reversing the tree only for now based on ur definition. Regards Ankur On Wed, Dec 21, 2011 at 1:08 PM

Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-20 Thread Ankur Garg
@Atul Even i thought so..but then the definition of leaf node is that its a node which doesnt have any children...then the answer is root of the original tree so I got confused here :( On Wed, Dec 21, 2011 at 12:20 AM, atul anand wrote: > @ankur : for the given tree above instead of par

Re: [algogeeks] Re: Reverse n-Ary Tree and Return List of Leaf Nodes as Output - FYI Google MV

2011-12-20 Thread Ankur Garg
Hey Shashank Unfortunately I cudnt understand the problem What do u mean by reversing the tree here :(.. On Tue, Dec 20, 2011 at 11:23 PM, WgpShashank wrote: > here is my code > > > List list=new LinkeList(); > > public List reverseTreeandReturnListContainingAllLeafNOdes(Node n) > { >in

[algogeeks] Can anyone help me with this problem

2011-12-19 Thread Ankur Garg
Hi Can anyone help me with this question Code for Serializing and Deserializing a binary 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, s

Re: [algogeeks] zig zag problem

2011-12-18 Thread Ankur Garg
as 4 whereas in the answer should be 3 Regards Ankur On Mon, Dec 19, 2011 at 1:16 AM, Ankur Garg wrote: > a linear solution for this problem . although its more than O(n) but will > never be O(n*2)..used DP to solve it > > space used -O(2n) > > int ZigZagLength(vector

Re: [algogeeks] zig zag problem

2011-12-18 Thread Ankur Garg
a linear solution for this problem . although its more than O(n) but will never be O(n*2)..used DP to solve it space used -O(2n) int ZigZagLength(vector a){ int n=a.size(); int DP[n][2]; DP[0][0]=1; DP[0][1]=0; DP[1][0]=2; DP[1][1]=0; int j; for(int i=2;i0){ if((a[i]-a[j])*(a[j]-a[DP[j][1]])<0){

[algogeeks] suggest algo

2011-12-17 Thread Ankur Garg
suggest algo to find k most frequently occuring numbers from a file of very large size containing numbers. -- 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 th

Re: [algogeeks] Re: find numbers if pair wise sums are given

2011-12-15 Thread Ankur Garg
I saw this term "non-decreasing order" So we need to sort the numbers first..it will take nlogn . On Fri, Dec 16, 2011 at 1:12 AM, Ankur Garg wrote: > on above algo , there is no need to calculate sum of array so we can do it > in O(N) and not O(n). > > > On Fri, Dec 16

Re: [algogeeks] Re: find numbers if pair wise sums are given

2011-12-15 Thread Ankur Garg
on above algo , there is no need to calculate sum of array so we can do it in O(N) and not O(n). On Fri, Dec 16, 2011 at 12:59 AM, Ankur Garg wrote: > Hi Topcoder. > > First of all you posted the wrong array . > > The array should be > > 4, 5, 10, 7,

Re: [algogeeks] Re: find numbers if pair wise sums are given

2011-12-15 Thread Ankur Garg
]=a+c = 4 and a[N-1] =a[7]=b+c=5 a[8]-a[1]= b-a=1 and a+b=a[0]=3 gives b=2 and a =1 Now we have a=1,b=2 So we traverse from a[1] to a[N-2] to calculate values c to h c= a[1]-a=4-1=3 d=a[2]-a=5-1=4 e=a[3]-a=6-1=5 similarly f=a[4]=6,g=a[5]=7 and h=a[6]=8 This will work in O(n) Regards Ankur On Thu, D

[algogeeks] Interesting Liked List problem..Suggest Algo

2011-12-15 Thread Ankur Garg
from p. 3. Space should not exceed by k units. 4. No saving of nodes to hard discs. 5. No recursion. Regards Ankur -- 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 u

[algogeeks] Suggest Algo for this Question

2011-12-13 Thread Ankur Garg
Given an array-based heap on n elements and a real number x, efficiently determine whether the kth smallest element in the heap is greater than or equal to x. Your algorithm should be O(k) in the worst-case, independent of the size of the heap. This question was also asked in Amazon -- You rece

Re: [algogeeks] Re: Find Largest number in log(n)

2011-12-12 Thread Ankur Garg
By Max Heapify I thought u meant to say u are making a Max Heap .. In case you use Coreman Definition Of max Heapify it just heapifies assuming the heap has been formed, But u need to make a max Heap first dude :) P.S-> Clarify your concepts before posting the link :( On Tue, Dec 13, 2011 at 12:1

Re: [algogeeks] Re: Find Largest number in log(n)

2011-12-12 Thread Ankur Garg
Max Heapify is O(n). On Mon, Dec 12, 2011 at 11:43 PM, ankit gupta wrote: > apply MAXHEAPIFY on root ode and extract the root node > > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@go

Re: [algogeeks] Re: Find Largest number in log(n)

2011-12-12 Thread Ankur Garg
Agree with dave..Its still O(n) On Mon, Dec 12, 2011 at 10:57 PM, Dave wrote: > @Sagar: Don is correct. n/2+n/4+n/8+... ~= n. But even the first > round, involving n/2 comparisons, is O(n). > > Dave > > On Dec 12, 11:23 am, sagar pareek wrote: > > Yes Mr. DoN > > > > First round of Tournament s

Re: [algogeeks] Detect a loop with just head ptr given

2011-12-08 Thread Ankur Garg
> of action.. > > On Thu, Dec 8, 2011 at 6:27 PM, Ankur Garg wrote: > >> Can we detect if a loop is present in Linked List if only head ptr is >> given >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorith

[algogeeks] Detect a loop with just head ptr given

2011-12-08 Thread Ankur Garg
Can we detect if a loop is present in Linked List if only head ptr is given -- 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 algoge

Re: [algogeeks] Thanks To aLgOgEeKs

2011-12-03 Thread Ankur Garg
cWas it offcampus or on campus recruitment dude. On Sat, Dec 3, 2011 at 12:5i7 PM, atul anand wrote: > @payal : last problem is a dutch flag problem. > > > On Sat, Dec 3, 2011 at 3:33 AM, payal gupta wrote: > >> congrats..:):) >> plzz...elaborate the last two problemsand it vud be very grate

Re: [algogeeks] Re: Google Question--Suggest Algo

2011-11-27 Thread Ankur Garg
ich is nothing but, > F(12, 3) = MAX > { > 1/2 + F(10, 2) , > 2/3 + F(9, 2) , > 2/4 + F(8, 2) , // this will yield the > maximum sum.. > 3/5 + F(7, 2) , >

Re: [algogeeks] Re: Google Question--Suggest Algo

2011-11-27 Thread Ankur Garg
: > > > > > > > > > > > > > > > > > Optimal split: [0,0][1,1][0,0][1,1][0,1][1,0] > > > Expected value of optimal split: 0 + 1 + 0 + 1 + 1/2 + 1/2 = 3 > > > why this is not the optimal split??? > > > > > On Sun, Nov 27,

Re: [algogeeks] Re: Finding the repeated element

2011-11-27 Thread Ankur Garg
> > 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. &

[algogeeks] Google Question--Suggest Algo

2011-11-27 Thread Ankur Garg
You have an array with *n* elements. The elements are either 0 or 1. You want to *split the array into kcontiguous subarrays*. The size of each subarray can vary between ceil(n/2k) and floor(3n/2k). You can assume that k << n. After you split the array into k subarrays. One element of each subarray

Re: [algogeeks] Re: Finding the repeated element

2011-11-24 Thread Ankur Garg
^^+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 b

Re: [algogeeks] Does Y lies between x and z

2011-11-24 Thread Ankur Garg
:( On Fri, Nov 25, 2011 at 12:57 AM, Ankur Garg wrote: > As it seems to me this can be solved like this > > Find LCA(Least common ancestor) of node x and z .. See if it equals y or > not . If not recursively search for y in left and right subtree of LCA ..If > you find y in the

Re: [algogeeks] Does Y lies between x and z

2011-11-24 Thread Ankur Garg
answer just that complexity would be a bit large (greater than n) but space wll be O(1) neglecting stack space during recursive calls I coded the same and it works to me .. If anyone can suggest a finer approach that wud be great :) Regards Ankur On Thu, Nov 24, 2011 at 11:28 PM, Nitin Garg

Re: [algogeeks] Re: An Array Problem

2011-11-23 Thread Ankur Garg
t; > while (p > 0 && stk[p - 1] >= in) p--; // pop > > a[i] = (p > 0) ? stk[p - 1] : 0; > > stk[p++] = in; // push > > } > > > > } > > > > On Nov 23, 5:13 am, Ankur Garg wrote: > > > > > > > > > Solutio

Re: [algogeeks] Re: An Array Problem

2011-11-23 Thread Ankur Garg
p.second]=0; } } On Wed, Nov 23, 2011 at 3:43 PM, Ankur Garg wrote: > Solution given by tech coder is fine and is working .. I coded it and its > working perfectly using stack > > > > On Wed, Nov 23, 2011 at 2:50 PM, Gene wrote: > >> It's a nice problem, and this

Re: [algogeeks] Re: An Array Problem

2011-11-23 Thread Ankur Garg
Solution given by tech coder is fine and is working .. I coded it and its working perfectly using stack On Wed, Nov 23, 2011 at 2:50 PM, Gene wrote: > It's a nice problem, and this solution is almost right. > > Process the input in _reverse_ order, which means we'll also generate > output in r

Re: [algogeeks] Re: Soritng

2011-11-20 Thread Ankur Garg
I think Merge Sort doesnt require any swapping . So , for 3 my answer wud be Merge Sort On Mon, Nov 21, 2011 at 11:55 AM, Dave wrote: > @Kumar: For question 1, the answer is radix sort. It doesn't use data > comparisons at all. > > Dave > > On Nov 21, 12:04 am, kumar raja wrote: > > if we have

[algogeeks] Linked List Problem-Suggest Algo

2011-11-20 Thread Ankur Garg
a linked list contains 2 19 _ _ 3 47 _ _ _ 2 20 _ _ ..and so on I have to fill those empty nodes with numbers whose sum is equal to the numbers occurring just before the gaps and the number of gaps is determined by the node which is at 2 distance before the gaps with the limitation that

Re: [algogeeks] Google Question--Suggest Algo

2011-11-16 Thread Ankur Garg
Can u provide a pseudo code for the same and c if it works On Thu, Nov 17, 2011 at 2:37 AM, sravanreddy001 wrote: > Start with counting sort of the input. > Use shuffling algorithm on it. > > Store index as cumulative sums of counts. > > -- > You received this message because you are subscribed

[algogeeks] Google Question--Suggest Algo

2011-11-16 Thread Ankur Garg
Given a string of lowercase characters, reorder them such that the same characters are at least distance d from each other. Input: { a, b, b }, distance = 2 Output: { b, a, b } How to approach this question ? -- You received this message because you are subscribed to the Google Groups "Algorit

Re: [algogeeks] Algm

2011-11-14 Thread Ankur Garg
Radix Sort On Mon, Nov 14, 2011 at 1:57 PM, Vijay Khandar wrote: > Which is the sorting algm sorts the integers [1...n^3] in > O(n). > a)Heapsort > b)Quicksort > c)Mergesort > d)Radix sort > > please tell anyone. > Vijay. > > -- > You received this message becaus

Re: [algogeeks] Amazon Onsite Chennai SDE

2011-11-14 Thread Ankur Garg
We can use a trie here .. Create a trie with all words of dictionary . Now delete the last character of the word and check if such a word is a valid word . If not see if adding a new character can make it a valid word . If not delete the next character and repeat the process again . This is what

[algogeeks] How to find highest power of 2 in an integer

2011-11-14 Thread Ankur Goel
How to find highest power of 2 in an integer Suppose number is 1 - Highest power of 2 is 1 00011 - Highest power of 2 is 2 11000 - Highest power of 2 is 5 No loops -- 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-11-12 Thread Ankur Garg
@Srinivas Wat if the string is abc then it reduces to cc :) ...So size 2 can also be there.so u cant say it will be 1 "always" On Sun, Nov 13, 2011 at 12:01 AM, Srinivasa Chaitanya T < tschaitanya@gmail.com> wrote: > > > On Sat, Nov 12, 2011 at 4:24 PM, Snoopy Me wrote: > >> Given a string

Re: [algogeeks] Re: Amazon Question

2011-11-12 Thread Ankur Garg
Well it aint O(n) ..:P ...The erase part will be complex and will take shifting string parts . So complexity will be O(n^2) for str.erase operation On Sat, Nov 12, 2011 at 8:34 PM, Ankur Garg wrote: > The Complexity of my solution is of Order n . At most I Traverse the whole > string

Re: [algogeeks] Re: Amazon Question

2011-11-12 Thread Ankur Garg
The Complexity of my solution is of Order n . At most I Traverse the whole string twice .. On Sat, Nov 12, 2011 at 8:29 PM, vikas wrote: > seems like quesion of permutation, it will take all the permutation to > check which one can lead to answer, there will be always be more than > one solutio

Re: [algogeeks] Amazon Question

2011-11-12 Thread Ankur Garg
Hey I coded it . The answer is either 2 or 1 ..So I guess you guys are rite :) Here is the code void smallestString(string &str){ if(str.empty()) return; int j=0,i,k=0; for(i=1;i0)j--; i=j; } } } On Sat, Nov 12, 2011 at 8:19 PM, Nitin Garg wrote: > If yes, how d

Re: [algogeeks] Amazon Question

2011-11-12 Thread Ankur Garg
Did they ask you to code this or just asked logic On Sat, Nov 12, 2011 at 4:57 PM, surender sanke wrote: > @myself > > if number of distinct characters are equal then its final string size is 2. > else there are more repeated characters other than distinct characters > then its 1 > > correct m

Re: [algogeeks] Amazon Onsite

2011-10-24 Thread Ankur Garg
think this way we just make at most 2 pass (in case the petrol pump of choice is just before the first point ) . Please comment in case you think its right/wrong Regards Ankur On Mon, Oct 24, 2011 at 10:15 PM, ravindra patel wrote: > @Nitin, excellent algo. > > >> if S < 0 &

Re: [algogeeks] Search an element in an Infinite array

2011-10-24 Thread Ankur Garg
change low=high and high = 2*high and again apply Binary Search. In the code before applying binary search u each time check whether k wrote: > @Ankur Don't think there's any major reason for using powers of 2 except > the fact that computing the powers of 2 can be done very

Re: [algogeeks] Search an element in an Infinite array

2011-10-23 Thread Ankur Garg
Use Binary Search start = 2^n-1 high =2^n where n=0,1 On Mon, Oct 24, 2011 at 12:28 AM, sunny agrawal wrote: > hint 1: try to find 2 indexes i, j such that a[i] <= K <= a[j] > > > On Sun, Oct 23, 2011 at 11:23 PM, Ankuj Gupta wrote: > >> Given a sorted array of Infinite size, find an elemen

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-22 Thread Ankur Garg
if you are dealing with some very large arrays. > > Dan :-) > > > On Oct 14, 9:44 pm, Ankur Garg wrote: > > @Dan ..can you post the algo here or link to the book?? > > @Anika ...yes please post the code here..but please explain a bit about > > underlying algo .

[algogeeks] Amazon Ques Suggest Algo

2011-10-19 Thread Ankur Garg
{You are given an unsorted array of integers. You have to find out the first sub array whose elements when added sum up to zero. eg:- int Array[] = {1,2,-4,-3, 6 ,-3.}Here sub array is -3,6,-3 bcos adding all these sum to zero. A sub array can be of size 2 to whole length of the array. You can

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-17 Thread Ankur Garg
@Shashank ..+1 ..I wud say he must be given a tuning award :D :D for solving such eternal conundrum ;) On Mon, Oct 17, 2011 at 2:37 PM, WgpShashank wrote: > @wladimir , its PPT (Pythagoras triplets ) but its number theory based > approach http://en.wikipedia.org/wiki/Pythagorean_triple might

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-17 Thread Ankur Garg
*Turing :P On Mon, Oct 17, 2011 at 3:51 PM, Ankur Garg wrote: > @Shashank ..+1 ..I wud say he must be given a tuning award :D :D for > solving such eternal conundrum ;) > > > > On Mon, Oct 17, 2011 at 2:37 PM, WgpShashank > wrote: > >> @wladimir , its PPT (Pythag

Re: [algogeeks] print vertical sums of a binary tree

2011-10-16 Thread Ankur Garg
t,level+1,minL,maxR,left,right); if(level<0) left[abs(level)] +=root->data; else right[level] +=root->data; } On Sun, Oct 16, 2011 at 4:23 PM, Ankur Garg wrote: > I am assuming we are allowed to use space ..With that i make 2 arrays 1 to > store values from left side and oth

Re: [algogeeks] print vertical sums of a binary tree

2011-10-16 Thread Ankur Garg
I am assuming we are allowed to use space ..With that i make 2 arrays 1 to store values from left side and other from right side . Here is the func void getLevelSum(node* root,int &minL,int &maxR,int level){ if(!root) return ; minL = min(minL,level); maxR = max(maxR,level); getLevelSum(root-

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-15 Thread Ankur Garg
@Sunny ..Superb Algo ..but can you share some link where we can read abt it :)..especially where the info abt the equation u used is given Thanks in Advance On Sat, Oct 15, 2011 at 12:37 PM, Kunal Patil wrote: > @Sunny: Thanks for the info !! That's gr8..& your logic also seems to be > workin

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-14 Thread Ankur Garg
@Dan ..can you post the algo here or link to the book?? @Anika ...yes please post the code here..but please explain a bit about underlying algo ...(algo is more important than actual code ) On Sat, Oct 15, 2011 at 1:54 AM, Dan wrote: > On Oct 13, 7:52 pm, "shiva@Algo" wrote: > > Convert an ar

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-14 Thread Ankur Garg
not sure how it will work in O(n) time then. >> >> Thanks, >> - Ravindra >> >> >> On Fri, Oct 14, 2011 at 12:25 AM, Ankur Garg wrote: >> >>> @rahul...How do u choose z and x for computing z^2 -x^2 ? >>> >>> On Thu, Oct 13, 2011 at

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread Ankur Garg
@rahul...How do u choose z and x for computing z^2 -x^2 ? On Thu, Oct 13, 2011 at 11:34 PM, rahul wrote: > You can create a hash with sqrt(z2-x2). This will make it o(n). The > interviewer just made it lil tricky. That's all > > -- > You received this message because you are subscribed to the Go

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread Ankur Garg
BTW can we solve this by hashing..That is the only feasible solution which comes to my mind to reduce the time complexity ? On Thu, Oct 13, 2011 at 11:20 PM, Ankur Garg wrote: > Dude this is nothing but 3 sum problem > > http://en.wikipedia.org/wiki/3SUM > > Ask interviewer to

Re: [algogeeks] Amazon Question - Find Pythagorean triplet in an unsorted array

2011-10-13 Thread Ankur Garg
Dude this is nothing but 3 sum problem http://en.wikipedia.org/wiki/3SUM Ask interviewer to check this link and say he has gone mad!! :P Regards Ankur On Thu, Oct 13, 2011 at 10:29 PM, ravindra patel wrote: > Hi, > Another question I faced in Amazon F2F. > > Given an unsor

Re: [algogeeks] remove duplicate words from a string

2011-10-10 Thread Ankur Garg
oo much space.. > Balanced Binary tree can be Better ...?? > > > On Tue, Oct 11, 2011 at 12:16 AM, Ankur Garg wrote: > >> I think this can be done through tries >> >> Any better solution ? >> >> On Mon, Oct 10, 2011 at 10:59 PM, sachin goyal wrote: >>

Re: [algogeeks] remove duplicate words from a string

2011-10-10 Thread Ankur Garg
I think this can be done through tries Any better solution ? On Mon, Oct 10, 2011 at 10:59 PM, sachin goyal wrote: > remove duplicate words from a string with min. complexityy. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To

Re: [algogeeks] Memorization

2011-10-10 Thread Ankur Garg
Memoization ? On Mon, Oct 10, 2011 at 6:34 PM, arvind kumar wrote: > Can anyone tell me how to go about with the memorization technique to > retrieve values from already stored values,in case of eveluating > sequences(fibonacci series,etc).? > > -- > You received this message because you are sub

Re: [algogeeks] Give Algo to do this in O(n)

2011-10-10 Thread Ankur Garg
@Sravan ..Counting Sort takes O(n) time but it needs range of nos to be known @Snehi jain..there is no range given so am not sure if count sort will work ,Can you please elaborate a bit on ur method Ankur On Mon, Oct 10, 2011 at 10:09 PM, sravanreddy001 wrote: > Just went throught what a co

[algogeeks] Algo for Search in a 2D Matrix

2011-10-09 Thread Ankur Garg
Given a 2D matrix which is both row wise and column wise sorted. Propose an algorithm for finding the kth smallest element in it in least time complexity A General Max Heap can be used with k space and n+klogk complexity Any other solution or even a way by which we dont scan the whole matrix to

[algogeeks] Give Algo to do this in O(n)

2011-10-09 Thread Ankur Garg
Given an unsorted array of Integers Find 2 nos whose diff is minimum Say Array is 4 2 18 19 11 8 5 Nos are 18 and 19 Algo shud be 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@goog

Re: [algogeeks] i cannot solve this written test question

2011-10-09 Thread Ankur Garg
Is it sum of bits or sum of digits ? On Sun, Oct 9, 2011 at 1:39 PM, wujin chen wrote: > Given a positive number N, find a minimum number M greater than N, M has > the same length with N and the sum of the bits are equal. > > example: > N=134 , M=143, // 1+3+4=1+4+3 > N=020, M = 101, //2=1+1 >

[algogeeks] Deletion in AVL tree

2011-10-08 Thread Ankur Garg
Can anyone suggest a pseudocode handling rotations in an AVL tree for deleting a node I couldnt find one in the internet and was unable to derive a proper logic which cud be transformed into code :( -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" g

Re: [algogeeks] Attention All Members

2011-10-08 Thread Ankur Garg
+1 On Sun, Oct 9, 2011 at 2:07 AM, Sunny wrote: > Now All of the messages are being Moderated and will be posted on the > group only if they are found relevant, any irrelevant post be simply > discarded without any notification till percentage of irrelevant posts > reduces by a significant amoun

[algogeeks] Efficient Algo for Merging 2 Binary Search Trees

2011-10-08 Thread Ankur Garg
Hi , Can anyone think of any better for doing this other than converting into List and then converting back again to BST .. Regards -- 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.

Re: [algogeeks] Algo for in-place Stack Reversal.

2011-10-07 Thread Ankur Garg
mpty()) { s. push(val); return; } temp = s.pop(); ReverseHelper(s,val); s.push(temp); } Remember to pass stack as reference Regards Ankur } On Fri, Oct 7, 2011 at 7:54 PM, sravanreddy001 wrote: > in place means: > > use constant extra space

Re: [algogeeks] amazon,microsoft link list probs

2011-10-05 Thread Ankur Garg
Implement recursive merge sort for first question For second just swap the values of node and node b On Wed, Oct 5, 2011 at 9:18 PM, 9ight coder <9ightco...@gmail.com> wrote: > 1.perform inplace(we cant create new node)merge sort of two sorted > linked list.(asked in amazon 1 mon before) > 2.a

[algogeeks] Amazon Ques

2011-10-04 Thread Ankur Garg
Find out the smallest segment in a document containing all the given words. Desired Complexity is O nlogK ..n is the total no of words in the document and k is the number of input words -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post

Re: [algogeeks] Re: string compress/expand

2011-10-03 Thread Ankur Garg
Code for Compression I am doing it inplace void convert(char* s,int len){ int i=0; int count=1; int index=1; //*maintain the index where number is to be added* for(i=1;i<=len;i++){ if(s[i]==s[i-1]) count++; else{ s[index-1]=s[i-1];*//put the cha

Re: [algogeeks] rise and fall of power

2011-10-03 Thread Ankur Garg
Keep an array to store multiplication of numbers like for input 9 3 U have to compute 9^9 So an array to store the digits and do simple multiplication like 9*9 will give 81 so Array will have 81 then 81*9 729 ..so on Then output the first k digits and last k digits of the array Any1 having

Re: [algogeeks] Re: Urgent sol needed

2011-10-03 Thread Ankur Garg
Many times this problem has been discussed ..Please check the archives yaar :( On Mon, Oct 3, 2011 at 11:39 PM, Shruti Gupta wrote: > I had inserted 0 instead of 1 The corrected code will be: > public static void setZeros(int[][] matrix) { >int[] row = new int[matrix.length]; >int[] col

[algogeeks] Can Any1 provide a proper implementation of a Hashtable(Seperation Chaining) in C,C++

2011-10-03 Thread Ankur Garg
-- 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 ht

Re: [algogeeks] suggestion

2011-10-03 Thread Ankur Garg
Committed to launch a website,formatting ..clarifying in case you mistook it for somethin else :D On Mon, Oct 3, 2011 at 7:50 PM, Ankur Garg wrote: > Nice Idea but for pulling this you need committed people :) > > On Mon, Oct 3, 2011 at 7:36 PM, sukran dhawan wrote: > >> Hell

  1   2   3   4   5   6   >