Re: [algogeeks] first unrepeated char

2010-10-12 Thread Mukesh Gupta
take two integer arrays A and B of size 26 ,A is for storing count and B is for index .Initialize both the array with 0's. Then iterate through the string once and keep incrementing the respective character count in A and store the character index in B. Now in array B find the minimum index whose

Re: [algogeeks] BST

2010-10-08 Thread Mukesh Gupta
4th element of inorder traversal On Fri, Oct 8, 2010 at 11:49 PM, Anand anandut2...@gmail.com wrote: Binary search Tree was given. Find 4ths smallest element. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] Re: Largest Rectangle in a binary Matrix:

2010-10-07 Thread Mukesh Gupta
AFAIK there is an O(n^3) solution to this problem. anybody with a O(n^2) or O(n) solution?? Mukesh Gupta Delhi College of Engineering On Thu, Oct 7, 2010 at 3:32 PM, tech rascal techrascal...@gmail.com wrote: can u plz xplain?? On Thu, Oct 7, 2010 at 2:32 PM, Chi c...@linuxdna.com

Re: [algogeeks] Duplicate in an array

2010-10-06 Thread Mukesh Gupta
. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Mukesh Gupta Delhi College of Engineering -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge

Re: [algogeeks] Re: Duplicate in an array

2010-10-06 Thread Mukesh Gupta
PM, Mukesh Gupta mukeshgupta.2...@gmail.comwrote: Keep inserting elements in a binary search tree and break once you get the find the element in the tree. Complexity=O(n log n) On 10/5/10, sourav souravs...@gmail.com wrote: You are given an array of positive numbers in which one

Re: [algogeeks] Re: Duplicate in an array

2010-10-06 Thread Mukesh Gupta
@Ankit: Insertion in hashmap in O(n) in worst case. As long as range of the numbers is not known we cannot predict whether the algo will run in linear time. Any other idea for O(n)?? Mukesh Gupta Delhi College of Engineering On Wed, Oct 6, 2010 at 4:32 PM, sourav souravs...@gmail.com wrote

Re: [algogeeks] All numbers in Array repeat twice except two

2010-10-04 Thread Mukesh Gupta
set bit. We can extract the rightmost set bit of any number n by taking ( n ~(n-1)) Here 2nd bit is the rightmost set bit. Now when we take xor of all values where 2nd bit is set(this could be done as (a[i] 0010) , we get 6 Taking xor of all values where 2nd bit is not set yields 4. Mukesh

Re: [algogeeks] Re: All numbers in Array repeat twice except two

2010-10-04 Thread Mukesh Gupta
For base conversion : int convert(int n,int from,int to) { int ret=0,i=0; while(n0) { ret=ret+(n%to)*pow(from,i++); n/=to; } return ret; } Mukesh Gupta Delhi Technological University On Mon, Oct 4, 2010 at 11:20 PM, Dave dave_and_da...@juno.com wrote: @Coolfrog

Re: [algogeeks] Re: All numbers in Array repeat twice except two

2010-10-04 Thread Mukesh Gupta
@coolfrog: problem statement says total number of elements is n .so overall complexity wud be O(n*logk) only. even i had the same doubt initially. Mukesh Gupta Delhi College of Engineering On Tue, Oct 5, 2010 at 12:46 AM, coolfrog$ dixit.coolfrog.div...@gmail.comwrote: @Dave yes it help

Re: [algogeeks] Re: binary matrix

2010-10-04 Thread Mukesh Gupta
,bottom.y)endlTotal number of 1's : max; } Mukesh Gupta Delhi College of Engineering On Mon, Oct 4, 2010 at 11:23 PM, Chi c...@linuxdna.com wrote: Maybe you meant this: Multidimensional Range Search in Dynamically Balanced Trees. http://www.vision-tools.com/h-tropf