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,
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
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
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
@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
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)
>>
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
@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
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.
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
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
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
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
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;
}
@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
@ 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?
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
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
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
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*
>
> --
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
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
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
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
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
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
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
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
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
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
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
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
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
>
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
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
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
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
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
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
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
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
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
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
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:
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
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
>
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.
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
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
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
>
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
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
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
@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
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
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
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
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,
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!
>>
>> --
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
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
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
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
@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
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
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
@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
@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:
>
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
@ 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
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
@ 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>>
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
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
@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
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...[?]
>>
@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
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
@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
@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
@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
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
@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
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
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:
@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
@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
Given an array A[i..j] find out maximum j-i such that A[i]http://groups.google.com/group/algogeeks?hl=en.
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
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
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
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=
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
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
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
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
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
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
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
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
101 - 200 of 289 matches
Mail list logo