Re: [algogeeks] Re: difference x

2010-12-23 Thread snehal jain
bhupendra's solution is right.. On Thu, Dec 23, 2010 at 1:04 PM, jai gupta sayhelloto...@gmail.com wrote: make another array(B) from (A) with all elements negated now find one element from B and one from A whose sum is x or -x. This can ofcourse be done in O(n). -- You received this

Re: [algogeeks] Re: difference x

2010-12-23 Thread Nikhil Agarwal
Divya and saurabh please post your working solution different from that of Bhupen's. On Thu, Dec 23, 2010 at 1:04 PM, jai gupta sayhelloto...@gmail.com wrote: make another array(B) from (A) with all elements negated now find one element from B and one from A whose sum is x or -x. This can

Re: [algogeeks] Re: difference x

2010-12-23 Thread Amit Jaspal
@ jai nice solution I think for O(n) solution we will have to use extra array. Otherwise we will have to do this in O(nlogn). Correct me if i am wrong. On Thu, Dec 23, 2010 at 1:04 PM, jai gupta sayhelloto...@gmail.com wrote: make another array(B) from (A) with all elements negated now find

[algogeeks] Re: difference x

2010-12-22 Thread juver++
There is simple solution of the similar problem: given sorted array, find two values which sum up to X. It can be solved with two pointers, such approach has been discussed on the forum some months ago. Your problem is similar. -- You received this message because you are subscribed to the

Re: [algogeeks] Re: difference x

2010-12-22 Thread Saurabh Koar
@Snehal: U r going crazy man.U r blindly picking up problems and throwing them in this group.It is not a place solving ur homework problems.Plz post problems which r either tricky so that the members can learn something or post problems which u cant solve after giving a measurable effort.Try to

Re: [algogeeks] Re: difference x

2010-12-22 Thread snehal jain
@saurabh u might be a genius bt for ur kind information this is the group for learners... this group is a place where people come to learn new tricks, put their ideas and ask doubts.. so it would have been better if u had put your response rather than discouraging anyone from asking doubts..

Re: [algogeeks] Re: difference x

2010-12-22 Thread Ankur Khurana
@snehal : nothing wrong in what saurabh said. it was just that if you are posting a question , then you should also post the approach you have thought.plus you are posting in bulk . so , please whenever you give a question , also mention your approach. it gives greater confidence in question to be

Re: [algogeeks] Re: difference x

2010-12-22 Thread snehal jain
@ankur.. its ok if u r asking for approach.. i ll do it from next tym.. bt posting in bulk is not an offence.. i bet u dont the solution to all my problems.. some of them u mite know some of them mite b new for u.. well same here u mite ask a prob and i mite find it easy.. i posted these problem

Re: [algogeeks] Re: difference x

2010-12-22 Thread Saurabh Koar
@Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which r very basic.As u solved the looping prob in other thread I think u r intelligent enough to solve this prob(difference x) easily and also some other probs posted by u(not all).Some problems posted by u are really very tricky

Re: [algogeeks] Re: difference x

2010-12-22 Thread Ankur Khurana
ya i agree , your questions are good though. On Wed, Dec 22, 2010 at 10:19 PM, snehal jain learner@gmail.com wrote: @ankur.. its ok if u r asking for approach.. i ll do it from next tym.. bt posting in bulk is not an offence.. i bet u dont the solution to all my problems.. some of them u

Re: [algogeeks] Re: difference x

2010-12-22 Thread Ankur Khurana
saurabh , asking for a better sol. is not a crime. rest everybody is intelligent. On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar saurabhkoar...@gmail.com wrote: @Snehal: I hv no problem wid ur doubts.Bt sometimes u post probs which r very basic.As u solved the looping prob in other thread I

Re: [algogeeks] Re: difference x

2010-12-22 Thread rajat ahuja
nyone like to post solution of ths problem, On Wed, Dec 22, 2010 at 10:28 PM, Ankur Khurana ankur.kkhur...@gmail.comwrote: saurabh , asking for a better sol. is not a crime. rest everybody is intelligent. On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar saurabhkoar...@gmail.com

Re: [algogeeks] Re: difference x

2010-12-22 Thread snehal jain
@ saurabh its fine.. nd can u plz tell ur soln to this prob.. i hv figured out an O(n) solution.. bt b4 dat i wanna knw ur solution.. On Wed, Dec 22, 2010 at 10:31 PM, rajat ahuja catch.rajatah...@gmail.comwrote: nyone like to post solution of ths problem, On Wed, Dec 22,

Re: [algogeeks] Re: difference x

2010-12-22 Thread juver++
Please don't use abbreviated words in your posts. Speak in pure English. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Re: difference x

2010-12-22 Thread rajat ahuja
saurabh .. i would like to know your solution can u please tell me ,, i want to know On Wed, Dec 22, 2010 at 11:50 PM, juver++ avpostni...@gmail.com wrote: Please don't use abbreviated words in your posts. Speak in pure English. -- You received this message because you are subscribed to the

[algogeeks] Re: difference x

2010-12-22 Thread Aviral Gupta
use hash map.O(n) or you can use use the binary search for each element O(nlogn) Regards Aviral http://coders-stop.blogspot.com On Dec 22, 3:05 pm, snehal jain learner@gmail.com wrote: How will you find the pair from an sorted array whose difference is x -- You received this

Re: [algogeeks] Re: difference x

2010-12-22 Thread bhupendra dubey
send the data set to the hash table now search for a[i]+x in the table if found for 'k' den a[k] and a[k]+x is the required pair complexity: o(n)(for mapping)+O(n)(for search a[i]+x)=O(n) @Snehal can i see your solution please. On Thu, Dec 23, 2010 at 12:11 AM, Aviral Gupta aviral@gmail.com

Re: [algogeeks] Re: difference x

2010-12-22 Thread juver++
Your solution needs extra space and it has only *expected* O(n) time. There is O(n) inplace solution -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Re: difference x

2010-12-22 Thread bhupendra dubey
@juver:thanx for making me work... please notice this this also uses the sorted property of the array i=0,j=1; while((i!=n-1) or j!=n) { /*compare difference of a[j] and a[i]*/ if( (a[j]-[a[i]])x ) i++; else if( (a[j]-a[i])x) j++; else { /*SOLUTION*/ return; } } regards complexity:O(n) On

Re: [algogeeks] Re: difference x

2010-12-22 Thread yq Zhang
@bhupendra Nice solution! Yq On Wed, Dec 22, 2010 at 11:29 AM, bhupendra dubey bhupendra@gmail.comwrote: @juver:thanx for making me work... please notice this this also uses the sorted property of the array i=0,j=1; while((i!=n-1) or j!=n) { /*compare difference of a[j] and a[i]*/

[algogeeks] Re: difference x

2010-12-22 Thread Minotauraus
Also a general FYI, please, please, please search before you post. Seeing the same Qs again and again for regulars isn't very interesting either. On Dec 22, 11:29 am, bhupendra dubey bhupendra@gmail.com wrote: @juver:thanx  for making me work... please notice this this also uses the sorted

Re: [algogeeks] Re: difference x

2010-12-22 Thread Divya Jain
@ saurabh and i wanna ur solution to this prob i know O(nlogn) post ur O(n) solution,. i hv some idea bt i wanna knw ur ans b4 mine On 22 December 2010 22:32, Divya Jain sweetdivya@gmail.com wrote: its okk On 22 December 2010 22:28, Ankur Khurana ankur.kkhur...@gmail.com wrote:

Re: [algogeeks] Re: difference x

2010-12-22 Thread Divya Jain
its okk On 22 December 2010 22:28, Ankur Khurana ankur.kkhur...@gmail.com wrote: saurabh , asking for a better sol. is not a crime. rest everybody is intelligent. On Wed, Dec 22, 2010 at 10:27 PM, Saurabh Koar saurabhkoar...@gmail.com wrote: @Snehal: I hv no problem wid ur doubts.Bt

Re: [algogeeks] Re: difference x

2010-12-22 Thread jai gupta
make another array(B) from (A) with all elements negated now find one element from B and one from A whose sum is x or -x. This can ofcourse be done in 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