[algogeeks] array question

2011-08-16 Thread MAC
Given an array of integers. Each number in the array repeats ODD number of times, but only 1 number repeated for EVEN number of times. Find that number. -- thanks --mac -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group,

Re: [algogeeks] array ques

2011-08-15 Thread siddharth srivastava
On 15 August 2011 21:07, sagar pareek wrote: > int lol=2; // total lol's encountered upto now > > lol++; it is a programming mistake as you have indicated the value of the important variable constant lol to 2 and then you have incremented it. :P > > > On Mon, Aug 15, 2011 at 12:41 AM, aditi g

Re: [algogeeks] array ques

2011-08-15 Thread sagar pareek
int lol=2; // total lol's encountered upto now lol++; On Mon, Aug 15, 2011 at 12:41 AM, aditi garg wrote: > lol > > > On Mon, Aug 15, 2011 at 12:40 AM, aditya kumar < > aditya.kumar130...@gmail.com> wrote: > >> @aditi : sry i dint realise that n > log n .:P >> >> On Mon, Aug 15, 2011 at 12:38 AM

Re: [algogeeks] array ques

2011-08-14 Thread aditi garg
lol On Mon, Aug 15, 2011 at 12:40 AM, aditya kumar wrote: > @aditi : sry i dint realise that n > log n .:P > > On Mon, Aug 15, 2011 at 12:38 AM, aditi garg wrote: > >> @aditya : dis is obviously correct bt here complexity will be O(n) bt we >> are asked to gv O(log n) solution >> >> On Mon, Aug

Re: [algogeeks] array ques

2011-08-14 Thread aditya kumar
@aditi : sry i dint realise that n > log n .:P On Mon, Aug 15, 2011 at 12:38 AM, aditi garg wrote: > @aditya : dis is obviously correct bt here complexity will be O(n) bt we > are asked to gv O(log n) solution > > On Mon, Aug 15, 2011 at 12:37 AM, aditya kumar < > aditya.kumar130...@gmail.com> wr

Re: [algogeeks] array ques

2011-08-14 Thread shady
lol On Mon, Aug 15, 2011 at 12:38 AM, aditi garg wrote: > @aditya : dis is obviously correct bt here complexity will be O(n) bt we > are asked to gv O(log n) solution > > > On Mon, Aug 15, 2011 at 12:37 AM, aditya kumar < > aditya.kumar130...@gmail.com> wrote: > >> for(j=0;j> { >> if(a[j]==j) >>

Re: [algogeeks] array ques

2011-08-14 Thread siddharth srivastava
Hi On 15 August 2011 00:37, aditya kumar wrote: > for(j=0;j { > if(a[j]==j) > return j; > else > continue ; > } > > this shud also be correct right ?? > It is a O(n) algo > > On Mon, Aug 15, 2011 at 12:31 AM, Akash Mukherjee wrote: > >> just my 2 cents in d binary search, replacing ke

Re: [algogeeks] array ques

2011-08-14 Thread aditi garg
@aditya : dis is obviously correct bt here complexity will be O(n) bt we are asked to gv O(log n) solution On Mon, Aug 15, 2011 at 12:37 AM, aditya kumar wrote: > for(j=0;j { > if(a[j]==j) > return j; > else > continue ; > } > > this shud also be correct right ?? > > On Mon, Aug 15, 2011 at 1

Re: [algogeeks] array ques

2011-08-14 Thread aditya kumar
for(j=0;jwrote: > just my 2 cents in d binary search, replacing key with mid, ie > if(a[mid] > mid) > check lower half > else upper half > > should work?? > > > On Mon, Aug 15, 2011 at 12:26 AM, aditi garg wrote: > >> Given an ordered array A[1…n] with numbers in strictly increasing >> order.

Re: [algogeeks] array ques

2011-08-14 Thread Akash Mukherjee
just my 2 cents in d binary search, replacing key with mid, ie if(a[mid] > mid) check lower half else upper half should work?? On Mon, Aug 15, 2011 at 12:26 AM, aditi garg wrote: > Given an ordered array A[1…n] with numbers in strictly increasing > order. Find a ‘j’ such that A [j]=j or -1

Re: [algogeeks] array ques

2011-08-14 Thread shady
already discussed... binary search :) On Mon, Aug 15, 2011 at 12:26 AM, aditi garg wrote: > Given an ordered array A[1…n] with numbers in strictly increasing > order. Find a ‘j’ such that A [j]=j or -1 if no such number exist in > o (log n). > > -- > You received this message because you are subs

[algogeeks] array ques

2011-08-14 Thread aditi garg
Given an ordered array A[1…n] with numbers in strictly increasing order. Find a ‘j’ such that A [j]=j or -1 if no such number exist in o (log 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@g

Re: [algogeeks] array question

2011-08-14 Thread shady
doesnt matter Order will be (nlogn) where n is max(elements in first set, elements in 2nd set) PS : dont submit codes from next time On Sun, Aug 14, 2011 at 7:43 PM, Nikhil Veliath wrote: > i feel binary search idea is the best > > guys i am having problem in finding out complexity...here i

Re: [algogeeks] array question

2011-08-14 Thread Nikhil Veliath
i feel binary search idea is the best guys i am having problem in finding out complexity...here is my solution to the above problem...whats the complexity... sort the 2 arraysa and b l=0,i=0,flag=0; while(a[i]=b[j]) { if(a[i]==b[j]) { printf("Common element is %d",a[i]); flag=1 break; }

Re: [algogeeks] array question

2011-08-14 Thread shady
@sagar suppose numbers are very large( > 10^9) , how will you hash then ? can you please state the hashing function in this case On Sun, Aug 14, 2011 at 6:50 PM, sagar pareek wrote: > Hashing > O(n+m) > > > On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro wrote: > >> how about binary search of ea

Re: [algogeeks] array question

2011-08-14 Thread Dipankar Patro
@ Sagar: What if extra space in not allowed? I think then we have to use the binary search method... On 14 August 2011 18:50, sagar pareek wrote: > Hashing > O(n+m) > > > On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro wrote: > >> how about binary search of each element from array 1 on array 2?

Re: [algogeeks] array question

2011-08-14 Thread sagar pareek
Hashing O(n+m) On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro wrote: > how about binary search of each element from array 1 on array 2? > > overall complexity : O(nlogn) > > On 14 August 2011 18:46, mohit verma wrote: > >> example: >> array 1 :: 1 2 3 4 5 6 7 8 9 10 15 >> array 2:: 23 34 5

Re: [algogeeks] array question

2011-08-14 Thread Dipankar Patro
how about binary search of each element from array 1 on array 2? overall complexity : O(nlogn) On 14 August 2011 18:46, mohit verma wrote: > example: > array 1 :: 1 2 3 4 5 6 7 8 9 10 15 > array 2:: 23 34 56 13 "15" 57 432 348 > > > On Sun, Aug 14, 2011 at 6:44 PM, shady wrote: > >> mea

Re: [algogeeks] array question

2011-08-14 Thread mohit verma
example: array 1 :: 1 2 3 4 5 6 7 8 9 10 15 array 2:: 23 34 56 13 "15" 57 432 348 On Sun, Aug 14, 2011 at 6:44 PM, shady wrote: > meaning ? what is a common element ? example ??? > > On Sun, Aug 14, 2011 at 6:37 PM, mohit verma wrote: > >> given two arrays : with all d

Re: [algogeeks] array question

2011-08-14 Thread shady
meaning ? what is a common element ? example ??? On Sun, Aug 14, 2011 at 6:37 PM, mohit verma wrote: > given two arrays : with all distinct elements but one element in common. > Find the common element in optimal time. > > -- > > *MOHIT VERMA* > > --

[algogeeks] array question

2011-08-14 Thread mohit verma
given two arrays : with all distinct elements but one element in common. Find the common element in optimal time. -- *MOHIT VERMA* -- 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] Array Problem

2011-08-14 Thread Yasir
any O(nlogn) solution? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/7Q8DHLIlbDoJ. To post to this group, send email to algogeeks@googlegroups.com. To uns

Re: [algogeeks] Array question: Detect whether a circular chain with all elements can be formed

2011-08-13 Thread Piyush Kapoor
Maybe you are looking for this:http://www.codechef.com/problems/WORDS1 On Sat, Aug 13, 2011 at 10:25 PM, Kamakshii Aggarwal wrote: > i got error,my sol will not work for all cases > > > On Sat, Aug 13, 2011 at 10:22 PM, Kamakshii Aggarwal < > kamakshi...@gmail.com> wrote: > >> see the following e

Re: [algogeeks] Array question: Detect whether a circular chain with all elements can be formed

2011-08-13 Thread Kamakshii Aggarwal
i got error,my sol will not work for all cases On Sat, Aug 13, 2011 at 10:22 PM, Kamakshii Aggarwal wrote: > see the following example: > *a*kdhd*a* ,*b*hdgd*c*, *c*hdjd*b* > > > On Sat, Aug 13, 2011 at 10:20 PM, Yasir wrote: > >> why following? >> >> if(first==last) >> return false; >> >> >> ex

Re: [algogeeks] Array question: Detect whether a circular chain with all elements can be formed

2011-08-13 Thread Kamakshii Aggarwal
see the following example: *a*kdhd*a* ,*b*hdgd*c*, *c*hdjd*b* On Sat, Aug 13, 2011 at 10:20 PM, Yasir wrote: > why following? > > if(first==last) > return false; > > > example: > axxa, ayyb, bzza ===> ayybbzzaaxxa > > -- > You received this message because you are subscribed to the Google Gr

Re: [algogeeks] Array question: Detect whether a circular chain with all elements can be formed

2011-08-13 Thread Yasir
why following? if(first==last) return false; example: axxa, ayyb, bzza ===> ayybbzzaaxxa -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/iONquZUgbP

Re: [algogeeks] Array question: Detect whether a circular chain with all elements can be formed

2011-08-13 Thread Kamakshii Aggarwal
maintain an array indexed on alphabets 'a' to 'z'. now count the occurence of each character taking *last character* of each string {"asdsb","csasaa", "bc", bc"} in this case arr[a]=1; arr[b]=1; arr[c]=2; now start with each sting let first character be first and last character be last wh

[algogeeks] Array question: Detect whether a circular chain with all elements can be formed

2011-08-13 Thread Yasir
An array of strings is given and you have to find out whether a circular chain with all character can be formed or not? Circular chain is formed in way that: if last char of a string is equal to first char of another string then it can be joined.: like ab bxc ===> axbbxc (N

Re: [algogeeks] array pointer

2011-08-05 Thread UTKARSH SRIVASTAV
I THINK THIS WILL CLEAR YOUR DOUBT x = address of first element of array=&x[0][0] *x=addrss of x[0][0]; **x=x[0][0] &x=address of x[0][0]; &x[0]=address of x[0][0]; &x[1]=address of x[1][0] *x[2]=address of x[2][0]; so 2 is wrong -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3Rd Year @MNNIT ALLAHABAD

Re: [algogeeks] array pointer

2011-08-05 Thread Amol Sharma
1 -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad On Fri, Aug 5, 2011 at 10:37 PM, Manish Sharma < manish.manishkumar.shar...@gmail.com> wrote: > 1 > > > On Fri, Aug 5, 2011 at 10:35 PM, Arshad Alam wrote: > >> >> we can equate base address of double dimen

Re: [algogeeks] array pointer

2011-08-05 Thread Manish Sharma
1 On Fri, Aug 5, 2011 at 10:35 PM, Arshad Alam wrote: > > we can equate base address of double dimension array to a pointer variable, > tell me which one is correct. if "n" is a pointer variable and x[5][5] is > double dimension array > >1. n=x; >2. n=x[0][0]; >3. both > > > -- > Yo

[algogeeks] array pointer

2011-08-05 Thread Arshad Alam
we can equate base address of double dimension array to a pointer variable, tell me which one is correct. if "n" is a pointer variable and x[5][5] is double dimension array 1. n=x; 2. n=x[0][0]; 3. both -- You received this message because you are subscribed to the Google Groups "Algor

Re: [algogeeks] array pointer

2011-08-05 Thread nishaanth
1 On Fri, Aug 5, 2011 at 5:47 PM, mohit goyal wrote: > n=x, is correct > or n = &x[0][0] is correct > > On 8/5/11, Arshad Alam wrote: > > we can equate base address of double dimension array to a pointer > variable, > > tell me which one is correct. if "n" is a pointer variable and x[5][5] is >

Re: [algogeeks] array pointer

2011-08-05 Thread mohit goyal
n=x, is correct or n = &x[0][0] is correct On 8/5/11, Arshad Alam wrote: > we can equate base address of double dimension array to a pointer variable, > tell me which one is correct. if "n" is a pointer variable and x[5][5] is > double dimension array > >1. n=x; >2. n=x[0][0]; >3. bot

[algogeeks] array pointer

2011-08-05 Thread Arshad Alam
we can equate base address of double dimension array to a pointer variable, tell me which one is correct. if "n" is a pointer variable and x[5][5] is double dimension array 1. n=x; 2. n=x[0][0]; 3. both -- You received this message because you are subscribed to the Google Groups "Algor

[algogeeks] array

2011-08-03 Thread Arshad Alam
can we insert 16 elements of one dimension array in 4*4 of double dimension array? -- 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] Array doubt

2011-07-30 Thread aditi garg
Can u please explain with the abv example how to maintain count aaray?? On Sun, Jul 31, 2011 at 12:28 AM, sukhmeet singh wrote: > maintain a count array of all elements.. > now traverse the array again and the count array .. and build the new array > > > On Sun, Jul 31, 2011 at 12:24 AM, aditi ga

Re: [algogeeks] Array doubt

2011-07-30 Thread sukhmeet singh
maintain a count array of all elements.. now traverse the array again and the count array .. and build the new array On Sun, Jul 31, 2011 at 12:24 AM, aditi garg wrote: > Q1) Given an array with some repeating numbers. Like 12,6,5,12,6 > output: 12,12,6,6,5 > > 12 shud come before 6 since it is e

[algogeeks] Array doubt

2011-07-30 Thread aditi garg
Q1) Given an array with some repeating numbers. Like 12,6,5,12,6 output: 12,12,6,6,5 12 shud come before 6 since it is earlier in list. Please provide a gud algo fr dis -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, s

Re: [algogeeks] array constant

2011-07-30 Thread prashant bhutani
If a compiler is compiling the code, simply means the compiler is intelligent enough to know what you want to do. But the language specifications, clearly explains not to do such things as these are non-portable!! Thanks & Regards, Prashant Bhutani Senior Undergraduate Computer Science & Engineeri

Re: [algogeeks] array constant

2011-07-30 Thread prashant bhutani
If the value can change then do the memory initialization at run-time using malloc/calloc. The line 5 is giving error because the declaration of an array (and so the allocation of memory) happens at compile time, while the initialization of the variables happen when the program is loaded for the ex

Re: [algogeeks] array constant

2011-07-30 Thread saurabh singh
yeah u can do any non executable statement before you declare the array.remove clrscr statement everything will be fine http://www.ideone.com/SpKpQ On Sat, Jul 30, 2011 at 1:16 PM, Bhanu Pratap Singh wrote: > In GCC, its okay!! > > > -- > You received this message because you are subscribed

Re: [algogeeks] array constant

2011-07-30 Thread Bhanu Pratap Singh
In GCC, its okay!! -- 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] array constant

2011-07-30 Thread sukhmeet singh
just adding to the concept.. this is not allowed since value of max may change during the program .. either by declaring it as a macro or as a const we (as said by ankur and varun ) restrict that the value from changing during the program ..!! On Sat, Jul 30, 2011 at 1:09 PM, Ankur Khurana wrote:

Re: [algogeeks] array constant

2011-07-30 Thread Ankur Khurana
or const int max=5; On Sat, Jul 30, 2011 at 1:09 PM, varun pahwa wrote: > make max as a macro. as for c static memory allocation take place either > with a constant or a macro. > i.e. > either u declare > #define max 5 > then write float arr[max]; > > or u may write > > float arr[5]; > > > > > On

Re: [algogeeks] array constant

2011-07-30 Thread varun pahwa
make max as a macro. as for c static memory allocation take place either with a constant or a macro. i.e. either u declare #define max 5 then write float arr[max]; or u may write float arr[5]; On Sat, Jul 30, 2011 at 1:05 PM, Arshad Alam wrote: > Why it is showing an error at line number 5 >

[algogeeks] array constant

2011-07-30 Thread Arshad Alam
Why it is showing an error at line number 5 1. void main() 2. { 3. clrscr(); 4. int i,max=5; 5. float arr[max]; 6. for(i=0;ihttp://groups.google.com/group/algogeeks?hl=en.

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 algoge

Re: [algogeeks] Array question

2011-07-26 Thread Piyush Sinha
Sorry for the above mistakeits not O(n) On Tue, Jul 26, 2011 at 5:29 PM, Piyush Sinha wrote: > Use stack > > > On Tue, Jul 26, 2011 at 5:22 PM, Shikhar wrote: > >> Given an array of integers, for each element of the array, print the >> first number on the right side of the element which is s

Re: [algogeeks] Array question

2011-07-26 Thread Piyush Sinha
Use stack On Tue, Jul 26, 2011 at 5:22 PM, Shikhar wrote: > Given an array of integers, for each element of the array, print the > first number on the right side of the element which is smaller than > it. print -1 is there is no such element. > > eg: 3,4,2,18,19,1,10 > > Ans: 2,2,1,10,10,-1,-1 >

[algogeeks] Array question

2011-07-26 Thread Shikhar
Given an array of integers, for each element of the array, print the first number on the right side of the element which is smaller than it. print -1 is there is no such element. eg: 3,4,2,18,19,1,10 Ans: 2,2,1,10,10,-1,-1 O(n^2) solution is trivial. One solution could be: Insert the elements of

Re: [algogeeks] Array traversal with rules..

2011-07-22 Thread Yuchen Liao
Yes, this is a simple DP problem: #include #include #define MAX 10 int main() { int n, a[100], dp[100]; while(scanf("%d", &n) == 1) { for(int i = 0; i < n; i++){ scanf("%d", &a[i]); dp[i] = MAX; } dp[n - 1] = 0; for(int i

[algogeeks] Array traversal with rules..

2011-07-22 Thread sukhmeet singh
You are given an array with some values..traverse the array according to the rule that if a[i]=x then you can jump max up to x steps.. (if a[i]=0 then you can't move any forward) find the least number of steps required to traverse the array ... EG:a[]=1 3 5 8 9 7 8 0 2 this requires 3 steps to tra

Re: [algogeeks] array or matrix problems...anyone?

2011-07-09 Thread Kunal Patil
@My post: matrix was randomly generated 3X3 matrix...(Not any 2D matrix) On Sat, Jul 9, 2011 at 9:08 PM, Kunal Patil wrote: > I had one in my MS apti... > Given a randomly generated 2 d matrix find an element which occurs in all 3 > rows... > > > On Sat, Jul 9, 2011 at 2:47 PM, Nitish Garg wrote

Re: [algogeeks] array or matrix problems...anyone?

2011-07-09 Thread Kunal Patil
I had one in my MS apti... Given a randomly generated 2 d matrix find an element which occurs in all 3 rows... On Sat, Jul 9, 2011 at 2:47 PM, Nitish Garg wrote: > I think Strassen Algorithm is used to multiply Matrices efficiently. Read > Cormen. > > -- > You received this message because you ar

Re: [algogeeks] array or matrix problems...anyone?

2011-07-09 Thread Nitish Garg
I think Strassen Algorithm is used to multiply Matrices efficiently. Read Cormen. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/qO_1-pri7WIJ. To post to

Re: [algogeeks] array or matrix problems...anyone?

2011-07-08 Thread oppilas .
What method did you used to multiply it efficiently? Any link for the same? On Fri, Jul 8, 2011 at 10:05 PM, Sriganesh Krishnan <2448...@gmail.com>wrote: > > ya...did that...anything else! > you know...like interview questions and stuff? > > On Fri, Jul 8, 2011 at 10:01 PM, shady wrote: > >> two

Re: [algogeeks] array or matrix problems...anyone?

2011-07-08 Thread Sriganesh Krishnan
ya...did that...anything else! you know...like interview questions and stuff? On Fri, Jul 8, 2011 at 10:01 PM, shady wrote: > two* > > > On Fri, Jul 8, 2011 at 10:00 PM, shady wrote: > >> try multiplying too matrices efficiently seems simple, doesn't >> it :P >> >> >> On Fri, Jul 8,

Re: [algogeeks] array or matrix problems...anyone?

2011-07-08 Thread shady
two* On Fri, Jul 8, 2011 at 10:00 PM, shady wrote: > try multiplying too matrices efficiently seems simple, doesn't > it :P > > > On Fri, Jul 8, 2011 at 9:40 PM, Sriganesh Krishnan <2448...@gmail.com>wrote: > >> can anybody suggest some good array or matrix related problems! >> >> --

Re: [algogeeks] array or matrix problems...anyone?

2011-07-08 Thread shady
try multiplying too matrices efficiently seems simple, doesn't it :P On Fri, Jul 8, 2011 at 9:40 PM, Sriganesh Krishnan <2448...@gmail.com>wrote: > can anybody suggest some good array or matrix related problems! > > -- > You received this message because you are subscribed to the Goog

[algogeeks] array or matrix problems...anyone?

2011-07-08 Thread Sriganesh Krishnan
can anybody suggest some good array or matrix related problems! -- 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

[algogeeks] array size problem

2011-07-03 Thread Deoki Nandan
WHY? In C++, you can do something like const int ArraySize = 100; int Array[ArraySize]; while in ANSI C, this would be flagged as an error. -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To

Re: [algogeeks] Array Merge Problem

2011-06-03 Thread Ashish Goel
true did not read the question properly... Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Fri, Jun 3, 2011 at 7:19 PM, Kunal Patil wrote: > @Ashish: your solution is not O(N). I dont think you are taking advantage > of the statement "( A and B

Re: [algogeeks] Array Merge Problem

2011-06-03 Thread Kunal Patil
@Ashish: your solution is not O(N). I dont think you are taking advantage of the statement "( A and B need not be sorted in the end)" @sravanreddy: excellent solution. On Thu, Jun 2, 2011 at 7:46 PM, Ashish Goel wrote: > > int i=lenA-1; > int j=lenB-1; > > while (j>=0) > { > if (A[i] >B[j]) {s

Re: [algogeeks] Array Merge Problem

2011-06-02 Thread Ashish Goel
int i=lenA-1; int j=lenB-1; while (j>=0) { if (A[i] >B[j]) {swap(A[i] ,B[j]); sort(A); } j--; } Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652 On Sat, May 28, 2011 at 11:09 PM, ross wrote: > Hi all, > Given 2 sorted arrays: A and B each ho

[algogeeks] Array Merge Problem

2011-05-28 Thread ross
Hi all, Given 2 sorted arrays: A and B each holding n and m elements respectively,. Hence, total no. of elements = m+n Give an algorithm to place the smallest 'm' elements(out of the m+n total available) in A and the largest 'n' elements in B. ( A and B need not be sorted in the end) eg: A : 1 2 3

Re: [algogeeks] Array problem

2011-05-22 Thread Azazle simon
@ps: ..:-) On 5/22/11, Piyush Sinha wrote: > @MONSIEUR.. > someone once said"THE SECRET OF SUCCESS IS TO NEVER REVEAL YOUR > SOURCES..." ;)...:P..:P > > On 5/22/11, MONSIEUR wrote: >> @piyush: excellent buddybtw what was the initial >> spark...???.:-) >> >> On May 21, 1:0

Re: [algogeeks] Array problem

2011-05-21 Thread Piyush Sinha
@Amit JaspalThe algo given by me works for the given case..check it On 5/20/11, Anurag Bhatia wrote: > Just need some clarification; sorry I joined the thread late. What are we > trying maximize? A[j] -A[i] such that i > --Anurag > > On Fri, May 20, 2011 at 12:34 AM, Kunal Patil wrote: >

Re: [algogeeks] Array problem

2011-05-20 Thread Anurag Bhatia
Just need some clarification; sorry I joined the thread late. What are we trying maximize? A[j] -A[i] such that i wrote: > @ Piyush: Excellent Solution...It appears both Correct and O(n)...Good work > !![?] > > Just a minor correction in your algo.[?] > > * while(B[i] * j++; > must

Re: [algogeeks] Array problem

2011-05-20 Thread Amit Jaspal
@ Above I think your solution would not work for A[] = {9,6,3,2,8,1} Ans is A[4]-A[1] > 0 i.e 4-1 = 3. On Tue, May 17, 2011 at 9:57 PM, Kunal Patil wrote: > Ohh..If it is so...Sorry !![?] I understood it the different way...[?] > But if the question is as mentioned in your 2nd case then also

Re: [algogeeks] Array problem

2011-05-20 Thread Terence
Try this case: 1000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1 On 2011-5-18 0:27, Kunal Patil wrote: Ohh..If it is so...Sorry !! I understood it the different way... But if the question is as mentioned in your 2nd case then also I believe there is O(n) solution. Mainta

Re: [algogeeks] Array problem

2011-05-19 Thread Kunal Patil
@ Piyush: Excellent Solution...It appears both Correct and O(n)...Good work !![?] Just a minor correction in your algo.[?] * while(B[i]http://groups.google.com/group/algogeeks?hl=en. <<363.gif>><<360.gif>>

Re: [algogeeks] Array problem

2011-05-18 Thread Piyush Sinha
last night i was going through a similar kind of question and tried to implement its algo in this question...If anyone finds any counter example for it, please do comment.. Algo:- *Let the array be A[]. We can keep two arrays B[] and C[] which will do the following work.. B[i] will store the mini

Re: [algogeeks] Array problem

2011-05-18 Thread Piyush Sinha
I think it can be done in O(n) but the auxilliary space required will be more... in the solution which i have got its in the order of 2n On Wed, May 18, 2011 at 4:44 PM, Kunal Patil wrote: > @Amit: Ohh..Your test case is correct but not my solution..[?] > It only works if it is guaranteed that o

Re: [algogeeks] Array problem

2011-05-18 Thread Kunal Patil
@Amit: Ohh..Your test case is correct but not my solution..[?] It only works if it is guaranteed that one end will be at the extreme of the array ! (UseLess ! [?]) Sorry folks... So can anybody prove that O(n) solution does not exist for this problem? [?] -- You received this message because you

Re: [algogeeks] Array problem

2011-05-18 Thread amit kumar
i dnt htink a o(n) soln exists for this problem. On Wed, May 18, 2011 at 3:47 PM, amit kumar wrote: > @kunal patil > your soln does not work for > 5 3 4 5 3 3 > > On Tue, May 17, 2011 at 9:57 PM, Kunal Patil wrote: > >> Ohh..If it is so...Sorry !![?] I understood it the different way...[?] >>

Re: [algogeeks] Array problem

2011-05-18 Thread amit kumar
@kunal patil your soln does not work for 5 3 4 5 3 3 On Tue, May 17, 2011 at 9:57 PM, Kunal Patil wrote: > Ohh..If it is so...Sorry !![?] I understood it the different way...[?] > But if the question is as mentioned in your 2nd case then also I believe > there is O(n) solution.[?] > > Maintain

Re: [algogeeks] Array problem

2011-05-17 Thread Kunal Patil
Ohh..If it is so...Sorry !![?] I understood it the different way...[?] But if the question is as mentioned in your 2nd case then also I believe there is O(n) solution.[?] Maintain two pointers: *START* and *END* two variables: max1 and max2 Assume arr[MAX_SIZE] to be the array containing

Re: [algogeeks] Array problem

2011-05-16 Thread Piyush Sinha
@kunal i think we both understood the problem differently...thats what i asked from amit..that whether in the window is it neccessary the elements in between should also be in increasing order or only the end elements should have the relation of one being greater than the other...I too thought

Re: [algogeeks] Array problem

2011-05-16 Thread Kunal Patil
@Anuj & Piyush: You didn't get the algo. It works on unsorted array also. You might have missed the statement *"else // next element is smaller than or equal to current element reset curr_max to 1;*" Here, the comment itself shows unsorted elements have been taken into consideration. If yo

Re: [algogeeks] Array problem

2011-05-16 Thread Piyush Sinha
@kunal.. anuj is right..ur code works only for sorted array...and I missed the part of doing it in O(n) time...I don't think there is way of doing it in O(n) time...if its there and if amit knows the solution, he should provide some hints... On 5/16/11, anuj agarwal wrote: > Kunal, > Your soluti

Re: [algogeeks] Array problem

2011-05-16 Thread anuj agarwal
Kunal, Your solution runs in O(n) time but it is a wrong solution. It will run fine if the array is sorted. Anuj Agarwal Engineering is the art of making what you want from things you can get. On Mon, May 16, 2011 at 7:17 PM, Kunal Patil wrote: > @Piyush Sinha: I doubt correctness of your sol

Re: [algogeeks] Array problem

2011-05-16 Thread Kunal Patil
@Piyush Sinha: I doubt correctness of your solution. And even if it gets out to be correct It is not O(n) My approach: Maintain 2 variables: curr_max and prev_max to keep knowledge about current maximum length and previous maximum length. Algorithm: *initialize curr_max and prev_max to 1 for i=0

Re: [algogeeks] Array problem

2011-05-15 Thread Piyush Sinha
how about this?? *int maxinterval(int a[],int i,int j) { if(i==j) return 0; int max1 = 0,max2; max2 = maxinterval(a,i+1,j); while(imax1) max1 =j-i; } i++; } return(max1>max2?max1:max2); } * On Mon, May 16, 2011 at 11:36 AM, anuj agarwal wrote: > How about create a BST and then, fo

Re: [algogeeks] Array problem

2011-05-15 Thread anuj agarwal
How about create a BST and then, for each node find the difference between the node and its child and do this for all except leaf nodes. If u want i will write the code for the same. Anuj Agarwal Engineering is the art of making what you want from things you can get. On Mon, May 16, 2011 at 11:

Re: [algogeeks] Array problem

2011-05-15 Thread anshu mishra
@amit ur code is wrong. just check it for this {5, 4, 1, 8, 4, 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 algogeeks+unsub

Re: [algogeeks] Array problem

2011-05-15 Thread Piyush Sinha
@amit jaspal I have doubt with your question...in the maximum window found i.e. A[i..j]...the elements should be in increasing order or only the end elements should have the relation of A[i] wrote: > Given an array A[i..j] find out maximum j-i such that A[i] O(n) time. > > -- > You received t

[algogeeks] Array problem

2011-05-13 Thread amit
Given an array A[i..j] find out maximum j-i such that A[i]http://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Array , Number Missing or Duplicate ..

2011-02-26 Thread radha krishnan
XOR :P On Sat, Feb 26, 2011 at 10:11 PM, bittu wrote: > Given an array of integers where some numbers repeat 1 time, some > numbers repeat 2 times and only one number repeats 3 times, how do you > find the number that repeat 3 times. > > > > Thanks > Shashank > > -- > You received this message be

[algogeeks] Array , Number Missing or Duplicate ..

2011-02-26 Thread bittu
Given an array of integers where some numbers repeat 1 time, some numbers repeat 2 times and only one number repeats 3 times, how do you find the number that repeat 3 times. Thanks Shashank -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. T

Re: [algogeeks] Array Question

2011-02-17 Thread Balaji Ramani
Here are two methods to do in O(n^2) 1) Insert elements of first array in hash and then for every pair of elements in (Bj, Ck) find if -(Bj + Ck) is in hash 2) Without extra space: sort arrays A and B now for each element in Ck find a pair (Ai, Bj) which sums to -Ck as below let p1 point to fi

Re: [algogeeks] Array Question

2011-02-17 Thread jalaj jaiswal
i have a n^2logn solution sort the third array,.. then for every pair in a and b search for the number which makes the sum zero using binary search but guess a better soln must exist On Thu, Feb 17, 2011 at 11:38 PM, bittu wrote: > We have three arrays > A=[a1,a2,...an] > B=[b1,b2,...bn] > C=

[algogeeks] Array Question

2011-02-17 Thread bittu
We have three arrays A=[a1,a2,...an] B=[b1,b2,...bn] C=[c1,c2,...cn] Write a method which takes these three arrays as input and return true if there is a combination [ai,bj,ck] such that ai+bj+ck = 0. O(n^3) solution is obvious. The questions is can we do better than this? Thanks & Reg

[algogeeks] array problem

2011-02-09 Thread jalaj jaiswal
sort the input array. only following operations on array is allowed: 1)get(index) -gets the element at that index 2)reverse(int start,int end) - example reverse(1,3) for the array [1,2,3,4,5] will return [1,4,3,2,5] better then nlogn -- With Regards, *Jalaj Jaiswal* (+919019947895) Software deve

Re: [algogeeks] array(amazon && microsoft)

2011-02-07 Thread jagannath prasad das
u can merge first two rows and proceed two at time.then slowly merge 4 at a tym and so on.a recursive algo will do On Mon, Feb 7, 2011 at 6:25 PM, Ashish Goel wrote: > yet to test... > will download xcode to compile, not on linux or windows (: > > remote case of all both entries in last

Re: [algogeeks] array(amazon && microsoft)

2011-02-07 Thread Ashish Goel
yet to test... will download xcode to compile, not on linux or windows (: remote case of all both entries in last row or last col needs to be looked.. int ai=1; int bi=0;int aj=0; int bj=1; int row = 0; int col=0; printf("%d \n", a[0][0]); while ((aiwrote: > here is the counter example.. below e

Re: [algogeeks] array(amazon && microsoft)

2011-02-07 Thread arpit busy in novels
hmm ya u need an extra K array but i think soln is fast do U On Mon, Feb 7, 2011 at 3:11 PM, jalaj jaiswal wrote: > for merge sort extra space will be needed > > > On Mon, Feb 7, 2011 at 3:10 PM, arpit busy in novels < > arpitbhatnagarm...@gmail.com> wrote: > >> Hey i m just a newbie To group BT

Re: [algogeeks] array(amazon && microsoft)

2011-02-07 Thread jalaj jaiswal
for merge sort extra space will be needed On Mon, Feb 7, 2011 at 3:10 PM, arpit busy in novels < arpitbhatnagarm...@gmail.com> wrote: > Hey i m just a newbie To group BTW from MNIT jaipur 3rd yr CS > > I just though we should apply merge sort < mean merge 2 array into one ) > on 1st row & 1st

Re: [algogeeks] array(amazon && microsoft)

2011-02-07 Thread arpit busy in novels
Hey i m just a newbie To group BTW from MNIT jaipur 3rd yr CS I just though we should apply merge sort < mean merge 2 array into one ) on 1st row & 1st column wrote: > isn't mnlog(mn)(simple quick sorting the entire array) better then > mnlog(m+n) > > > > On Mon, Feb 7, 2011 at 2:46 PM, sunny

Re: [algogeeks] array(amazon && microsoft)

2011-02-07 Thread jalaj jaiswal
isn't mnlog(mn)(simple quick sorting the entire array) better then mnlog(m+n) On Mon, Feb 7, 2011 at 2:46 PM, sunny agrawal wrote: > one of the possible methods is to use concept same as EXTRACT-MIN of heaps > > do the following steps *m*n *times > 1. print a[0][0] ans replace this by a[m-1][n-1

<    1   2   3   >