Re: [algogeeks] Re: Printing random word from file

2012-08-26 Thread Kunal Patil
Okay..missed it..thnx fr info..
Your approach is nice..it took me some time to understand your code's
though.. Great answer!!
On Aug 26, 2012 3:55 AM, "Dave"  wrote:

> @Kunal: Yes. You are missing that you don't know the number of words in
> the file in advance. So, to use your method, you would have to read the
> file once to find n, and then read through it again to select the lucky_pos
> th word. The method I proposed only requires reading the file once.
>
> Furthermore, assuming that rand() produces a random non-negative integer,
> rand()%n is not equiprobable for all values of n. Consider n = 3. Then
> since rand() takes on 2^31 values, rand()%3 cannot take on the values 0, 1,
> and 2 with equal probability since 2^31 is not divisible by 3.
>
> Dave
>
> On Saturday, August 25, 2012 1:44:03 PM UTC-5, Kunal Patil wrote:
>
>> How about using rand()%n ??
>> Like, calculate lucky_pos = rand()%n
>> Then print word at lucky_pos th position...
>> Am I missing anything? All words are still equiprobable to get printed
>> right?
>> On Aug 20, 2012 11:45 AM, "Dave"  wrote:
>>
>>> @Navin: Okay. Here is a paraphrase. Assume double function random()
>>> returns a uniformly distributed random number >= 0.0 and < 1.0.
>>>
>>> read first word from file into string save;
>>> int i = 1
>>> while not EOF
>>> {
>>> read next word from file into string temp;
>>> i++;
>>> if( i * random() < 1.0 )
>>> copy temp to save;
>>> }
>>> print save;
>>>
>>> Dave
>>>
>>> On Monday, August 20, 2012 12:02:54 AM UTC-5, Navin Kumar wrote:
>>>
>>>> @Dave sir, I didn't get your logic. Can you please elaborate it?
>>>>
>>>> On Sun, Aug 19, 2012 at 4:08 AM, Dave  wrote:
>>>>
>>>>> @Navin: Here is the algorithm:
>>>>>
>>>>> Save the first word.
>>>>> For i = 2, 3, ..., n = number of words in the file
>>>>> replace the saved word with the i-th word with probability 1/i.
>>>>> When EOF is reached, every word in the file will have probability 1/n
>>>>> of being the saved word. Print it.
>>>>>
>>>>> Dave
>>>>>
>>>>> On Saturday, August 18, 2012 1:28:56 AM UTC-5, Navin Kumar wrote:
>>>>>
>>>>>> Print a *Random word* from a file. Input is "path to a file",
>>>>>>
>>>>>> constraints- No extra memory like hashing etc. All the words in the
>>>>>> file should have equal probability.
>>>>>
>>>>>  --
>>>>> 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/*
>>>>> *ms**g/algogeeks/-/HxO-wNzEP9gJ<https://groups.google.com/d/msg/algogeeks/-/HxO-wNzEP9gJ>
>>>>> .
>>>>>
>>>>> To post to this group, send email to algo...@googlegroups.com.
>>>>> To unsubscribe from this group, send email to algogeeks+...@**
>>>>> googlegroups.com**.
>>>>> For more options, visit this group at http://groups.google.com/**group
>>>>> **/algogeeks?hl=en <http://groups.google.com/group/algogeeks?hl=en>.
>>>>>
>>>>
>>>>  --
>>> 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/-/crET-x06vpkJ<https://groups.google.com/d/msg/algogeeks/-/crET-x06vpkJ>
>>> .
>>> To post to this group, send email to algo...@googlegroups.com.
>>> To unsubscribe from this group, send email to algogeeks+...@**
>>> googlegroups.com.
>>> For more options, visit this group at http://groups.google.com/**
>>> group/algogeeks?hl=en <http://groups.google.com/group/algogeeks?hl=en>.
>>>
>>  --
> 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/-/pvqb27sRhFAJ.
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Printing random word from file

2012-08-25 Thread Kunal Patil
How about using rand()%n ??
Like, calculate lucky_pos = rand()%n
Then print word at lucky_pos th position...
Am I missing anything? All words are still equiprobable to get printed
right?
On Aug 20, 2012 11:45 AM, "Dave"  wrote:

> @Navin: Okay. Here is a paraphrase. Assume double function random()
> returns a uniformly distributed random number >= 0.0 and < 1.0.
>
> read first word from file into string save;
> int i = 1
> while not EOF
> {
> read next word from file into string temp;
> i++;
> if( i * random() < 1.0 )
> copy temp to save;
> }
> print save;
>
> Dave
>
> On Monday, August 20, 2012 12:02:54 AM UTC-5, Navin Kumar wrote:
>
>> @Dave sir, I didn't get your logic. Can you please elaborate it?
>>
>> On Sun, Aug 19, 2012 at 4:08 AM, Dave  wrote:
>>
>>> @Navin: Here is the algorithm:
>>>
>>> Save the first word.
>>> For i = 2, 3, ..., n = number of words in the file
>>> replace the saved word with the i-th word with probability 1/i.
>>> When EOF is reached, every word in the file will have probability 1/n of
>>> being the saved word. Print it.
>>>
>>> Dave
>>>
>>> On Saturday, August 18, 2012 1:28:56 AM UTC-5, Navin Kumar wrote:
>>>
 Print a *Random word* from a file. Input is "path to a file",

 constraints- No extra memory like hashing etc. All the words in the
 file should have equal probability.
>>>
>>>  --
>>> 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/-/HxO-wNzEP9gJ
>>> .
>>>
>>> To post to this group, send email to algo...@googlegroups.com.
>>> To unsubscribe from this group, send email to algogeeks+...@**
>>> googlegroups.com.
>>> For more options, visit this group at http://groups.google.com/**
>>> group/algogeeks?hl=en .
>>>
>>
>>  --
> 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/-/crET-x06vpkJ.
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Spoj Domino Tiling

2012-02-10 Thread Kunal Patil
Which traditional approach you are talking about? :-o I haven't solved many
of such problems and thus dunno the tradition.. :P

Whenever I see such type of problems what I do is calculate maximum number
of basic blocks we can form.
Once this is done, problem can be solved recursively.
But the problem here is: In this question, for each n there is a unique
structure which you cannot construct using basic blocks.
Thus, i am not able to get the simple recurrence, instead I get the
recurrence having n terms which I think is impossible to solve.
Any link on basics will be appreciated. :) :)


On Thu, Feb 9, 2012 at 11:47 PM, shady  wrote:

> well i have used three recurrences :P formed them by following a
> traditional approach
>
> f[i] = f[i-1] + 2*g[i-1] + h[i-1] + f[i-2];
>g[i] = f[i-1] + g[i-1];
>h[i] = f[i-1] + h[i-2];
>
>
>
> On Thu, Feb 9, 2012 at 7:19 PM, Kunal Patil  wrote:
>
>> I am solving spoj problem Tiling a Grid With
>> Dominoes.(http://www.spoj.pl/problems/GNY07H/)..
>> I am not able to come up with a recurrence relation..
>> One of my friend said it has the recurrence relation as f(n) = f(n-1)
>> + 5*f(n-2) + f(n-3) - f(n-4).
>> I am not convinced and have trouble deriving this formula from given
>> data..Can somebody help??
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Spoj Domino Tiling

2012-02-09 Thread Kunal Patil
I am solving spoj problem Tiling a Grid With
Dominoes.(http://www.spoj.pl/problems/GNY07H/)..
I am not able to come up with a recurrence relation..
One of my friend said it has the recurrence relation as f(n) = f(n-1)
+ 5*f(n-2) + f(n-3) - f(n-4).
I am not convinced and have trouble deriving this formula from given
data..Can somebody help??

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



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

2011-11-01 Thread Kunal Patil
@shady: There were no specific constraints. Actually, they didn't expect
any best solution. People who wrote brute force also got shortlisted. Brute
force would be Just picking a number one by one from first row and then
checking other rows for existence of this number. I think it is a O(n^3)
algorithm where n--> number of rows/cols

Another approach might be, we can sort each row in O(nlogn). So total is
O(n^2 * log(n)). Take number one by one from first row and then binary
search on remaining rows. It is O(logn) in one row. So total binary search
cost for searching one element in n rows is O(nlogn). In worst case where
last element of first row occurs in each row, complexity of this algorithm
seems to be O(n^2 * logn )

Correct me if I'm wrong. Anyone having better solution to this, please
comment..

Also as second algorithm is quite complex to implement and in question they
explicitly mentioned matrix is 3X3, So brute force would be the fastest i
guess... :) :)

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] [SPOJ] ZSUM

2011-10-25 Thread Kunal Patil
Can you tell why (x * z * z) % MOD is different from (x * ( (z*z)%MOD) ) %
MOD

Again why ((x%MOD)*(z%MOD)*(z%MOD))%MOD is giving WA 

I thought of a simple examples like
(100* 53*72) % 90
  --> ((90+10)*53*72) % 90
  --> (10*53*72)% 90   which is same as (100%90 * 53%90 * 72%90) % 90

Another example
(100*91*92)%90
   --> ( (90+10)*(90+1)*(90+2) ) % 90
   --> 10 * 1 * 2 which is again same as (100%90 * 91%90 * 92%90) % 90

Are results different because of range overflow in case of bigger z ???

I'm weak at modular mathematics [?] So please help !!


On Thu, Oct 20, 2011 at 11:48 AM, Wasif Hossain
wrote:

> Just a MINOR change.
> please change the RED line(I've marked it below) in your code by the
> following line:
> *return (x*((z*z)%MOD))%MOD;*
> and enjoy an *ACCEPTED *verdict.*
> *
>
> *Wasif Hossain**
> *
> B.Sc. Student of Final Semester,
> Computer Science and Engineering(CSE),
> Bangladesh University of Engineering and Technology(BUET),
> Dhaka-1000
> Bangladesh.
>
> On Thu, Oct 6, 2011 at 1:13 AM, hashd  wrote:
>
>> I'm getting WA on the question : 
>> ZSUM-SPOJ
>>
>> Here is my code: 
>>
>>
>> #include
>> #define MOD 1007
>>
>> typedef unsigned long long u64;
>> using namespace std;
>>
>> u64 modExp(u64 x, u64 y){
>> if(x==0)
>> return 0;
>>
>> if(y==0)
>> return 1;
>>
>> u64 z = modExp(x,y/2);
>>
>> if(y%2==0)
>> return (z*z)%MOD;
>> else
>> *return (x*z*z)%MOD;*
>> }
>>
>> int main(){
>> u64 n, k; scanf("%llu%llu",&n,&k);
>> while(n&&k){
>> u64 ans = 0;
>>
>> if(n>0)
>> ans = (2*modExp(n-1,k) + modExp(n,k) + 2*modExp(n-1,n-1) +
>> modExp(n,n))%MOD;
>>
>> printf("%llu\n",ans);
>> scanf("%llu%llu",&n,&k);
>> }
>>
>> return 0;
>> }
>>
>> --
>> 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/-/p6j7nmaEUb4J.
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<33D.gif>>

Re: [algogeeks] Re: Inplace Array Convertion

2011-10-15 Thread Kunal Patil
@Sunny: Thanks for the info !! That's gr8..& your logic also seems to be
working perfectly fine..

On Sat, Oct 15, 2011 at 12:16 PM, shady  wrote:

> u can always post the code.,... but before posting code, you must state
> your algorithm
>   else code becomes useless for other users
>
> On Sat, Oct 15, 2011 at 1:10 AM, Anika Jain wrote:
>
>> i have the code solution to this.. if m allowed to post it here then i can
>> i post it. m i allowed to post code here?
>>
>>
>> On Fri, Oct 14, 2011 at 9:40 PM, gaurav yadav 
>> wrote:
>>
>>> @shiva...keep swapping the underline elements
>>>
>>> a1*a2*a3a4a5*b1*b2b3b4b5c1c2c3c4c5
>>> a1b1*a3*a4a5a2b2b3b4b5*c1*c2c3c4c5
>>> a1b1c1*a4*a5*a2*b2b3b4b5a3c2c3c4c5
>>> a1b1c1a2*a5*a4*b2*b3b4b5a3c2c3c4c5
>>> a1b1c1a2b2*a4*a5b3b4b5a3*c2*c3c4c5
>>> a1b1c1a2b2c2*a5*b3b4b5*a3*a4c3c4c5
>>> a1b1c1a2b2c2a3b3*b4*b5a5a4*c3*c4c5
>>> a1b1c1a2b2c2a3b3c3*b5*a5*a4*b4c4c5
>>> a1b1c1a2b2c2a3b3c3a4*a5*b5*b4*c4c5
>>> a1b1c1a2b2c2a3b3c3a4b4*b5*a5*c4*c5
>>> a1b1c1a2b2c2a3b3c3a4b4*c4*a5*b5*c5
>>> a1b1c1a2b2c2a3b3c3a4b4c4a5b5c5
>>>
>>>
>>>
>>>  --
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] New Group For Practicing and Learning Efficient Ways of Coding

2011-10-05 Thread Kunal Patil
Great work shady...+1
I was so bored of the company interview queries on this group..
Hope to see Real algorithmic discussion on the new group.

On Wed, Oct 5, 2011 at 11:27 PM, KARTHIKEYAN V.B.  wrote:

> +1
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Explain output

2011-09-29 Thread Kunal Patil
Why don't you post a code that compiles ?

On Fri, Sep 30, 2011 at 12:41 AM, Brijesh wrote:

> void main()
>
>  {
> void *ptr;
> char *a='A';
> char *b="TAN";
> int i=50;
> ptr=a;
> ptr=(*char)malloc(sizeof(a));
> printf("%c",*ptr);
> ptr=i;
> ptr=(*int)malloc(sizeof(i));
> printf("%d",++(*ptr));
> ptr=b;
> ptr=(*char)malloc(sizeof(b));
> printf("%c",++(*ptr));
>
> }
> ptr=(*char)malloc(sizeof(a));
> Ans: A51AN
>
> Please explain the output..
> Doesnt this line   ptr=(* char)malloc(sizeof(i))
>
> initialize ptr to NULL
>
> --
> 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/-/QRNgJFXBZawJ.
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Amazon OS question

2011-09-26 Thread Kunal Patil
Nice question & nice answer... :)

On Tue, Sep 27, 2011 at 6:25 AM, UTKARSH SRIVASTAV
wrote:

> what's the algo of this question
>
>
> On Mon, Sep 26, 2011 at 2:38 PM, vikas wrote:
>
>> simple graph question,
>> graph is given as list , just check the dependancy
>>
>> On Sep 25, 6:25 pm, siva viknesh  wrote:
>> > thanks a lot yogesh...
>> >
>> > On Sep 25, 2:23 pm, Yogesh Yadav  wrote:
>> >
>> > > T1->T2->T3->T6
>> > > T1->T2->T4->T7
>> > > T1->T2->T5->T8
>> >
>> > > 2 Processor:
>> > > (T1->T2) ..2 TS
>> > > (T3&T4)...1 TS
>> > > (T6&T5)...1 TS
>> > > (T7&T8)...1 TS
>> >
>> > > 4 Processor
>> > > (T1->T2) ..2 TS
>> > > (T3&T4&T5)...1 TS
>> > > (T6&T7&T8)...1 TS
>> >
>> > > .
>> > > On Sun, Sep 25, 2011 at 2:33 PM, siva viknesh > >wrote:
>> >
>> > > > plz give detailed explanation
>> >
>> > > > On Sep 25, 1:58 pm, siva viknesh  wrote:
>> > > > > can u plz giv the sequence
>> >
>> > > > > On Sep 25, 11:36 am, Sanjay Rajpal  wrote:
>> >
>> > > > > > yah rite answer would be 5 and 4 resp.
>> > > > > > Sanju
>> > > > > > :)
>> >
>> > > > > > On Sat, Sep 24, 2011 at 10:04 PM, Dheeraj Sharma <
>> >
>> > > > > > dheerajsharma1...@gmail.com> wrote:
>> > > > > > > 5 & 4?
>> >
>> > > > > > > On Sun, Sep 25, 2011 at 9:33 AM, sivaviknesh s <
>> > > > sivavikne...@gmail.com>wrote:
>> >
>> > > > > > >> A parallel program consists of 8 tasks – T1 through T8. Each
>> task
>> > > > requires
>> > > > > > >> one time step to be executed on a single processor. Let X ->
>> Y
>> > > > denote the
>> > > > > > >> fact that task X must be executed before task Y is executed.
>> Suppose
>> > > > only
>> > > > > > >> the tasks X, Y are to be executed. On any multiprocessor
>> machine it
>> > > > would
>> > > > > > >> require at least 2 time steps since in the first step X could
>> be
>> > > > executed,
>> > > > > > >> and Y could be executed in the next time step (since it
>> requires X
>> > > > to
>> > > > > > >> complete first). Now, suppose the following dependencies
>> exist
>> > > > between the
>> > > > > > >> tasks T1 – T8:
>> >
>> > > > > > >> T1 -> T2
>> >
>> > > > > > >> T2 -> T3
>> >
>> > > > > > >> T3 -> T6
>> >
>> > > > > > >> T2 -> T4
>> >
>> > > > > > >> T4 -> T7
>> >
>> > > > > > >> T2 -> T5
>> >
>> > > > > > >> T5 -> T8
>> >
>> > > > > > >> What is the minimum number of time steps required to execute
>> these 8
>> > > > tasks
>> > > > > > >> on a 2 processor machine and a 4 processor machine?
>> >
>> > > > > > >> a)4 & 2
>> >
>> > > > > > >> b)5 & 2
>> >
>> > > > > > >> c)5 & 4
>> >
>> > > > > > >> d)6 & 2
>> >
>> > > > > > >> --
>> > > > > > >> Regards,
>> > > > > > >> $iva
>> >
>> > > > > > >> --
>> > > > > > >> 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
>> > > > > > >>http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > > > > > > --
>> > > > > > > *Dheeraj Sharma*
>> > > > > > > Comp Engg.
>> > > > > > > NIT Kurukshetra
>> >
>> > > > > > > --
>> > > > > > > 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
>> > > > > > >http://groups.google.com/group/algogeeks?hl=en.
>> >
>> > > > --
>> > > > 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
>> > > >http://groups.google.com/group/algogeeks?hl=en.
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> *UTKARSH SRIVASTAV
> CSE-3
> B-Tech 3rd Year
> @MNNIT ALLAHABAD*
>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscr

Re: [algogeeks] output

2011-09-13 Thread Kunal Patil
@Kumar: +1

@Kumar & Rajeshwar: ExitFailure is outputted because main is expected to
return something which is not done in your case. Just add return 0; at the
end of main to get expected output.

On Tue, Sep 13, 2011 at 11:33 PM, Ishan Aggarwal <
ishan.aggarwal.1...@gmail.com> wrote:

> int main()
> {printf("%s",printf("samsung")+fun());
> return 0;}fun(){return "electronic";}
>
>
>
>
> On Tue, Sep 13, 2011 at 11:28 PM, kumar raja wrote:
>
>> main(){printf("%s",printf("samsung")+fun());}fun(){return "electronic";}
>>
>> The printf is a function which returns the number of printed characters , 
>> and scanf is a function
>> which returns the number of inputs scanned .
>>
>> So after printing "samsung" it returns 7. fun() is returning a pointer to 
>> the constant string
>>
>>
>> "electronic" , so it is like 7["electronic"]
>>
>> so the %s prints that string from the 7th index onwards till end .
>>
>> So output is "nic"
>>
>> so the total output is "samsungnic"
>>
>>
>> but i dont know why it is exiting with some error code..
>>
>>
>>
>> On 13 September 2011 10:51, Rajeshwar Patra wrote:
>>
>>> http://codepad.org/erdnF74M
>>>
>>> can anyone explain the output ???
>>>
>>> --
>>> *Rajeshwar Patra,*
>>> *MCA final year,*
>>> *Nit Durgapur*
>>>
>>>  --
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Regards
>> Kumar Raja
>> M.Tech(SIT)
>> IIT Kharagpur,
>> 10it60...@iitkgp.ac.in
>> 7797137043.
>> 09491690115.
>>
>>  --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Kind Regards
> Ishan Aggarwal
> [image: Aricent Group]
> Presidency Tower-A, M.G.Road,Sector-14
> Gurgaon,Haryana.122015 INDIA
> Phone : +91-9654602663
> ishan2.aggar...@aricent.com 
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C Puzzle

2011-09-12 Thread Kunal Patil
Allocate memory for pointer variables.

On Mon, Sep 12, 2011 at 11:03 AM, sukran dhawan wrote:

> run time error
> first int * a is not assigned some address... so it will be pointing to
> some garbage value
> second two pointers of different types without  a typecast will result in
> unpredictable results
>
> On Mon, Sep 12, 2011 at 10:25 AM, teja bala wrote:
>
>> #include
>> main()
>> {
>> int *a;
>> char *c;
>> *a = 20;
>> *c = *a;
>> printf("%d %c",*a,*c);
>> }
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Amazon ques

2011-09-11 Thread Kunal Patil
As the author correctly mentions it:
"Building the array is O(n) , but printing these intervals must be done in
linear time to the number of intervals."
Assuming n means number of elements in the original array
There are O(n^2) possible intervals, how can you print them in O(n) ???

On Sun, Sep 11, 2011 at 4:20 PM, Ankur Garg  wrote:

> This solution is not in O(n) time :(
> Unfortunately interviewer wants O(n) .
>
>
> On Sun, Sep 11, 2011 at 4:01 PM, Kunal Patil  wrote:
>
>> @Brijesh: +1
>>
>>
>> On Sun, Sep 11, 2011 at 2:14 PM, Brijesh wrote:
>>
>>>  This is the fastest way I can think of to do this, and it is linear to
>>> the number of intervals there are.
>>>
>>> Let L be your original list of numbers and A be a hash of empty arrays
>>> where initially A[0] = [0]
>>>
>>> sum = 0
>>> for i in 0..n
>>>   if L[i] == 0:
>>> sum--
>>> A[sum].push(i)
>>>   elif L[i] == 1:
>>> sum++
>>> A[sum].push(i)
>>>
>>> Now A is essentially an x y graph of the sum of the sequence (x is the
>>> index of the list, y is the sum). Every time there are two x values x1 and
>>> x2 to an y value, you have an interval (x1, x2] where the number of 0s and
>>> 1s is equal.
>>>
>>> There are m(m-1)/2 (arithmetic sum from 1 to m - 1) intervals where the
>>> sum is 0 in every array M in A where m = M.length
>>>
>>> Using your example to calculate A by hand we use this chart
>>>
>>> L   #   0  1  0  1  0  0  1  1  1  1  0
>>> A keys  0  -1  0 -1  0 -1 -2 -1  0  1  2  1
>>> L index-1   0  1  2  3  4  5  6  7  8  9  10
>>>
>>> (I've added a # to represent the start of the list with an key of -1.
>>> Also removed all the numbers that are not 0 or 1 since they're just
>>> distractions) A will look like this:
>>>
>>> [-2]->[5]
>>> [-1]->[0, 2, 4, 6]
>>> [0]->[-1, 1, 3, 7]
>>> [1]->[8, 10]
>>> [2]->[9]
>>>
>>> For any M = [a1, a2, a3, ...], (ai + 1, aj) where j > i will be an
>>> interval with the same number of 0s as 1s. For example, in [-1]->[0, 2, 4,
>>> 6], the intervals are (1, 2), (1, 4), (1, 6), (3, 4), (3, 6), (5, 6).
>>>
>>> Building the array A is O(n), but printing these intervals from A must be
>>> done in linear time to the number of intervals. In fact, that could be your
>>> proof that it is not quite possible to do this in linear time to n because
>>> it's possible to have more intervals than n and you need at least the number
>>> of interval iterations to print them all.
>>>
>>> Unless of course you consider building A is enough to find all the
>>> intervals (since it's obvious from A what the intervals are), then it is
>>> linear to n
>>>
>>> THis is the solution..go through it, its very easy to understand...
>>> PS: copied from
>>>
>>> http://stackoverflow.com/questions/6967853/dynamic-programming-can-interval-of-even-1s-and-0s-be-found-in-linear-time
>>>
>>>
>>>
>>>
>>>
>>> --
>>> 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/-/wM8Xhc1tUXQJ.
>>>
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Amazon ques

2011-09-11 Thread Kunal Patil
@Brijesh: +1

On Sun, Sep 11, 2011 at 2:14 PM, Brijesh wrote:

> This is the fastest way I can think of to do this, and it is linear to the
> number of intervals there are.
>
> Let L be your original list of numbers and A be a hash of empty arrays
> where initially A[0] = [0]
>
> sum = 0
> for i in 0..n
>   if L[i] == 0:
> sum--
> A[sum].push(i)
>   elif L[i] == 1:
> sum++
> A[sum].push(i)
>
> Now A is essentially an x y graph of the sum of the sequence (x is the
> index of the list, y is the sum). Every time there are two x values x1 and
> x2 to an y value, you have an interval (x1, x2] where the number of 0s and
> 1s is equal.
>
> There are m(m-1)/2 (arithmetic sum from 1 to m - 1) intervals where the sum
> is 0 in every array M in A where m = M.length
>
> Using your example to calculate A by hand we use this chart
>
> L   #   0  1  0  1  0  0  1  1  1  1  0
> A keys  0  -1  0 -1  0 -1 -2 -1  0  1  2  1
> L index-1   0  1  2  3  4  5  6  7  8  9  10
>
> (I've added a # to represent the start of the list with an key of -1. Also
> removed all the numbers that are not 0 or 1 since they're just distractions)
> A will look like this:
>
> [-2]->[5]
> [-1]->[0, 2, 4, 6]
> [0]->[-1, 1, 3, 7]
> [1]->[8, 10]
> [2]->[9]
>
> For any M = [a1, a2, a3, ...], (ai + 1, aj) where j > i will be an interval
> with the same number of 0s as 1s. For example, in [-1]->[0, 2, 4, 6], the
> intervals are (1, 2), (1, 4), (1, 6), (3, 4), (3, 6), (5, 6).
>
> Building the array A is O(n), but printing these intervals from A must be
> done in linear time to the number of intervals. In fact, that could be your
> proof that it is not quite possible to do this in linear time to n because
> it's possible to have more intervals than n and you need at least the number
> of interval iterations to print them all.
>
> Unless of course you consider building A is enough to find all the
> intervals (since it's obvious from A what the intervals are), then it is
> linear to n
>
> THis is the solution..go through it, its very easy to understand...
> PS: copied from
>
> http://stackoverflow.com/questions/6967853/dynamic-programming-can-interval-of-even-1s-and-0s-be-found-in-linear-time
>
>
>
>
>
> --
> 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/-/wM8Xhc1tUXQJ.
>
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: worst case complexity

2011-09-10 Thread Kunal Patil
Sorry for one small mistake in my analysis.
I forgot summation includes extreme values also, in the calculation.
So, final number of iteration is for

for(int i=1;i<=(n);i++)
for(int j=1;j<=(i*i);j++)
for(int k=1;k<=(j);k++)
{
}

But this mistake doesn't have any effect on the O(n^5) Time complexity. :)
:)



On Sat, Sep 10, 2011 at 5:10 PM, Kunal Patil  wrote:

> @Piyush: In 2 ways I will prove you wrong.
>
> 1)
> Lets take 2 innermost loops.
>
> for(j=0;j {
>
> for(k=0;k }
>
> Let i*i be m. Thus, It becomes.
>
> for(j=0;j {
>
> for(k=0;k }
>
> You would agree that this is O(m^2).
> This means innermost two loops constitute O(m^2) --> O(( i^2) ^ 2) --> O(i
> ^ 4)
>
> Outer loop iterates over i once till n.
> So,
> for i=0 it will run O(i^4=0) times
> for i=1 it will run O(i^4=1) times
> for i=2 it will run O(i^4=16) times
> for i=n it will run O(n^4) times.
>
> Summing all them up, its O(n^5).
>
> 2)
> Lets represent given loops by summations:
>
> for(i=0;i summation_i_from_0_to_n
> {
> for(j=0;j summation_j_from_0_to_i^2
> {
> for(k=0;k summation_k_from_0_to_j
>
> So To calculate exact number of iterations you would need to solve these
> nested summations.
>
> Steps:
> 1) Initially we have,
> summation_i_from_0_to_n ( summation_j_from_0_to_i^2
> (summation_k_from_0_to_j (constant) ))
>
> 2) Innermost summation evaluates to j
>
> So now we are left with -->
> summation_i_from_0_to_n ( summation_j_from_0_to_i^2  ( j )  )
>
> 3) Innermost evaluates to (i^2)*(i^2 + 1) /2
>
> So now we are left with -->
> summation_i_from_0_to_n ( (i^2)*(i^2 + 1) /2 )
>
> 4) This evalutes to
>
> (1/2) { (6*n^5 + 15n^4 + 10n^3 - n) / 30 } + (1/2) { n*(n+1)*(2n+1) / 6 }
> which is equal to the exact number of iterations.
>
> This is clearly O(n^5).
>
> Correct me If I am wrong anywhere in the analysis...
>
>
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: worst case complexity

2011-09-10 Thread Kunal Patil
@Piyush: In 2 ways I will prove you wrong.

1)
Lets take 2 innermost loops.

for(j=0;j O(( i^2) ^ 2) --> O(i ^
4)

Outer loop iterates over i once till n.
So,
for i=0 it will run O(i^4=0) times
for i=1 it will run O(i^4=1) times
for i=2 it will run O(i^4=16) times
for i=n it will run O(n^4) times.

Summing all them up, its O(n^5).

2)
Lets represent given loops by summations:

for(i=0;i summation_i_from_0_to_n
{
for(j=0;j summation_j_from_0_to_i^2
{
for(k=0;k summation_k_from_0_to_j

So To calculate exact number of iterations you would need to solve these
nested summations.

Steps:
1) Initially we have,
summation_i_from_0_to_n ( summation_j_from_0_to_i^2
(summation_k_from_0_to_j (constant) ))

2) Innermost summation evaluates to j

So now we are left with -->
summation_i_from_0_to_n ( summation_j_from_0_to_i^2  ( j )  )

3) Innermost evaluates to (i^2)*(i^2 + 1) /2

So now we are left with -->
summation_i_from_0_to_n ( (i^2)*(i^2 + 1) /2 )

4) This evalutes to

(1/2) { (6*n^5 + 15n^4 + 10n^3 - n) / 30 } + (1/2) { n*(n+1)*(2n+1) / 6 }
which is equal to the exact number of iterations.

This is clearly O(n^5).

Correct me If I am wrong anywhere in the analysis...

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Kth largest element

2011-09-10 Thread Kunal Patil
@Dave: TC in your first case will be O(klogn + n).
Transforming array into heap would be O(n).
Correct me If i am 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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks]

2011-09-10 Thread Kunal Patil
@Piyush: +1

On Sat, Sep 10, 2011 at 1:07 AM, Piyush Grover wrote:

> pseudo algo:
>
> =>array idx[0...k-1]  indicates the current pointer position in the ith
> stream(initialized to 0).
> =>heap tree of size k where each node stores value of the data and value of
> stream which the node belongs to.
>
> do{
>for all i = 0:k-1
>   =>insert idx[i] value of ith stream to the heap
>
>=>take the root element of the heap and put it in the output stream.
>=>idx[m]++ where m is the stream value stored at the root.
>
> } while(true);
>
>
>
> On Sat, Sep 10, 2011 at 12:15 AM, aditya kumar <
> aditya.kumar130...@gmail.com> wrote:
>
>> Given k sorted streams where each stream could possibly be infinite in
>> length, describe an efficient algorithm to merge the k streams into a new
>> stream (also in sorted order).
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] ACM

2011-09-08 Thread Kunal Patil
Cool.. If you can share/ask algorithm related programming questions.. :)
In fact it is the main cause of this group. :) :) :)
There are sufficient SPOJ problem discussions over here..
You can continue asking questions if you think, that particular problem
needs special data handling techniques to make it pass all the large test
cases... :)

On Fri, Sep 9, 2011 at 11:00 AM, Manish Verma wrote:

> Hey, anyone preparing for acm-icpc
>
> what about discussing acm-icpc questions here
> what say @shady??
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re:

2011-09-06 Thread Kunal Patil
@siddharam suresh: sizeof(void) is an prohibited operation. So your code
would result in compile time error.

On Tue, Sep 6, 2011 at 11:47 PM, siddharam suresh
wrote:

> my guess,
> sizeof() takes only the declaration properties not the definition
> properties(that means it wont call the function)
>
>
> *#include*
> *void c(); *
> *int main()*
> *{*
> *printf("%d",sizeof(c()));*
> *}*
> *void c()*
> *{*
> *printf("c"); *
> *}*
> *o/p:*
> *1*
>
>
> Thank you,
> Sid.
>
>
>
> On Tue, Sep 6, 2011 at 11:41 PM, siddharam suresh  > wrote:
>
>> its size of return type, but why the above program not showing
>> segmentation fault?
>> Thank you,
>> Sid.
>>
>>
>>
>> On Tue, Sep 6, 2011 at 11:34 PM, ankush garg  wrote:
>>
>>> better contact AKSHAY CHADHA .. the person is quite good at c and
>>> algos currently placed in MICROSOFT..
>>> akshay.chadha...@gmail.com
>>> 9899466888
>>>
>>> --
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] EOF

2011-09-06 Thread Kunal Patil
If I understand question correctly, then just read as many characters as you
can using standard string functions. (like fgets n all related)
Output these all characters in a file.
Iterate until you have read all the characters and go on appending what you
have read to file.
You intended to ask something else?

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re:

2011-09-06 Thread Kunal Patil
sizeof never executes whatever expression is given as parameter.
It needs only size of parameter.
In this case, parameter main() returns an int type.
So sizeof returns sizeof int. It doesnt need to call main() to get its task,
of finding size, done.

On Tue, Sep 6, 2011 at 11:41 PM, siddharam suresh
wrote:

> its size of return type, but why the above program not showing segmentation
> fault?
> Thank you,
> Sid.
>
>
>
> On Tue, Sep 6, 2011 at 11:34 PM, ankush garg  wrote:
>
>> better contact AKSHAY CHADHA .. the person is quite good at c and
>> algos currently placed in MICROSOFT..
>> akshay.chadha...@gmail.com
>> 9899466888
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] c doubt

2011-08-31 Thread Kunal Patil
@kartik:
typedef struct
{
int bit1:29;
int bit2:4;
}bit;
This makes total number of bits 33, which is not on int boundry. (multiple
of 32 bits)
So to make it aligned on int boundry, 31 extra bits  are padded at the end
of bit2.
This makes size of struct 29 + 4 + 31 = 64 bits --> 8 bytes.
When bit1 + bit2 = multiple of 32, No need for alignment arises.

Similar example is
struct{
   int x;
   char y;
   }temp;
Here int --> 32 bits
char --> 8 bits
Total = 40 bits. Not a multiple of 32 bits thus, it is forcefully aligned
along int boundary by padding 24 bits.
If you are confused about all this, Google padding in struct.

On Wed, Aug 31, 2011 at 10:34 PM, kartik sachan wrote:

> @ prateek i am still not geeting why now out put is 4
> but if we change second bit2:5 then out put again 8
> plzz explain throughly
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Zig Zag tree traversal

2011-08-28 Thread Kunal Patil
@ Kartikeyan:
If you use normal queue implementation how you are going to print reverse???

(From ptr2 to ptr1)...If you are implementing queue in an array, then your
solution can be feasible..
If not in array, you must modify your queue DS to include pointers to
previous elements.
Or you can do this by emptying queue into stack n then printing nodes...
Am I getting it correct? Or is there anything I am missing?

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread Kunal Patil
@Dave: Still your approach to solve the problem remains correct.
(subtracting a number from max possible value & then comparing this
difference with another number). So, no need to think that you were brain
dead (If you were, you would have posted a movie story here)..[?]
Mathematically it is wrong, not in terms of approach..[?]

On Sat, Aug 27, 2011 at 11:02 PM, dipit grover wrote:

> I think you just need to reverse the comparison operators in Dave's earlier
> post
>
>
> On Sat, Aug 27, 2011 at 10:59 PM, Dave  wrote:
>
>> @Abishek: I was brain-dead in my earlier posting. Let me try again:
>>
>> If either number is zero, the sum will not overflow.
>> If the numbers have different signs, the sum will not overflow.
>> If both numbers are positive, overflow will occur if b > maxint - a.
>> If both numbers are negative, overflow will occur if b < -maxint - a -
>> 1.
>>
>> Dave
>>
>> On Aug 27, 12:18 pm, Abhishek  wrote:
>> > @Dave: i didn't understand,
>> > suppose a=3, b=31000 and MaxInt=32000;
>> > you are saying if (MaxInt-a)>=b; then overflow will occur. but here
>> > condition is not satisfying.
>> > plz explain.
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> Dipit Grover
> B.Tech in CSE
> IIT Roorkee
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<361.gif>><<360.gif>>

Re: [algogeeks] Re: Problem on overflow

2011-08-27 Thread Kunal Patil
@Dave: +1 for nice solution... :)

On Sat, Aug 27, 2011 at 10:12 PM, Dave  wrote:

> @Avinash: What do you mean by "exceeding limit(already overflowed)"?
> The number maxint is the limit. Every positive number is <= maxint.
>
> Dave
>
> On Aug 27, 10:31 am, "Avinash LetsUncomplicate.."  2...@gmail.com> wrote:
> > @dave if number a is entered exceeding limit(already overflowed) then
> > a goes negative(if a was entred just more than limit ) /a goes
> > positive (if a was entred sufficiently more than limit )  maxint -a>=b
> > concept fails
> >
> > Avinash Katiyar
> > NIT Allahabad
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Google Question:Given a BST and a number, Find the closest node to that number in the BST.

2011-08-20 Thread Kunal Patil
@Abhishek:
Its not always that you reach a leaf through the node.
But still your logic seems correct.
There would be 3 candidates for minimum:
-->predecessor
-->current node
-->successor.

On Sat, Aug 20, 2011 at 1:13 PM, Abhishek Yadav
wrote:

> No your solution is correct tooits just that in your solution number of
> comparisons done with the original number are more, while in my solution
> they get down to 2. otherwise complexities of both the solution would be
> O(log n).
> I am stressing on no. of comparisons because in these kind of questions
> where we do compare something no. of comparisons matters.
> for example when we talk about finding largest and second largest in an
> array, we do try to minimize number of comparisons.
>
> Otherwise your solution is correct no doubt.
>
>
> On Sat, Aug 20, 2011 at 12:59 PM, Dipankar Patro wrote:
>
>> is there anything wrong in my algo?
>> do tell me.
>>
>>
>> On 20 August 2011 12:56, Abhishek Yadav wrote:
>>
>>> Hey i tried it now and got to another solution
>>> O(log n) solution:
>>> 1. try searching for the number , if found,return the node, otherwise,
>>> you will ultimately reach a leaf node say 'nd'
>>> 2.  Now the two candidates for the answer would be
>>>1. TreeSuccessor(nd)  2. TreePredecessor(nd)
>>> Now compare the original number with these two and minimum would be the
>>> answer.
>>>
>>> (TreeSuccessor and TreePredecessor are the next and previous node resp.
>>> in the Inorder traversal of the tree.)
>>>
>>> On Sat, Aug 20, 2011 at 12:46 PM, Dipankar Patro wrote:
>>>
 why traverse the whole tree?

 at each root keep the difference in a min_diff and min_ele.
 if the entered value is less root then move to left or right.
 repeat above two until whole tree is checked or min_diff becomes 0.

 pseudo code:

 min_diff = INF; // global variables
 min_ele = 0;

 find_min_diff(node *root, int num)
 {

  if (root == null)
  return;

 // update the difference
  if(abs(root->val - num) < min_diff)
  {
   min_diff = abs(root->val - num);
   min_ele = root->val;
  }
  if ( min_diff == 0)
   return; // search is over

 // proceed to next element in tree which might be closer to the num
  if ( num < root-> val)
find_min_ele(root->left, num);
  else
find_min_ele(root->right, num);
 }

 ^^ Complexity : O(logn)

 On 20 August 2011 12:36, Abhishek Yadav wrote:

> yes, the interviewer said that there is a solution in O(log n)
>
>
> On Sat, Aug 20, 2011 at 12:29 PM, sukran dhawan <
> sukrandha...@gmail.com> wrote:
>
>> ur traversing the tree once so it shud be o(n).does the question
>> demand 0(logn) ?
>>
>> On Sat, Aug 20, 2011 at 12:27 PM, Abhishek Yadav <
>> algowithabhis...@gmail.com> wrote:
>>
>>> what would be the complexity of your solution O(n) or O(log n)..?
>>>
>>>  On Sat, Aug 20, 2011 at 12:19 PM, sukran dhawan <
>>> sukrandha...@gmail.com> wrote:
>>>
 traverse bst inorder and each time u encounter a node find the
 difference between the element and given element in question . if the
 absolute difference is minimum after traversing the tree that is the 
 element
 . u can getback the element using another element which keeps sign of 
 the
 element so that original element can be obtained from diff

 On Sat, Aug 20, 2011 at 12:15 PM, Abhishek Yadav <
 algowithabhis...@gmail.com> wrote:

> Given a BST and a number, Find the closest node to that number in
> the
> BST. Give an algorithm for that.
> Let there be binary search tree having nodes with values
> 12,34,64,23,64,25,76,6 and the number given is 28, then the answer
> would be 25 as it is the closest 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@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
  --
 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
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email t

Re: [algogeeks] Re: Possible solutions to these sort of Questions

2011-08-18 Thread Kunal Patil
+1 Yasir.

On Wed, Aug 17, 2011 at 11:39 PM, Yasir  wrote:

> For questions specifically asking about test cases, I would suggest
> following 3 step approach:
>
> First think of a* basic flow that MUST work for the application* (what is
> expected with the application. Firstly make it clear with you interviewer).
>  eg:
>  1) User should be able to open Notepad without any error/warning.
>  2) User should be seamlessly able to type characters. (should not be
> the case, where you are typing and it appears after some time)
>  3) Create one file using notepad, close the application and reopen the
> file. (make sure, result is as expected)
>  ..and so on (try to cover all basic functionality). Also you can
> club few test cases. eg, for menu features you can say something like:
> verify that all menu options are working as expected.
>
>
> Now move one step ahead, and *think of a person who is not familiar with
> the application* (what would he do?):
>   eg:
>1) User should be able open the Help docs and help docs should be
> relevant.
>2) If a user writes something, forgets to save and trying to close
> the application: Appropriate notification.
>3) Trying to copy and paste with supported/unsupported format.
>4) Drag/drop a file on the application.
> and so on...
>
> and then comes *negative test cases* (it may happen rarely but it is very
> important):
>   eg:
>   1) Trying to open multiple instances of the application
> (application shouldn't act weird)
>   2) Crash the application and open it next time. It should open (may
> be with some notification), but the application SHOULDN'T CORRUPT.
>   3) Application behavior when you open very large file. (should give
> appropriate warning, if it is going to take longer time/crash)
>   4) behavior with unsupported file.  (eg: trying to open a .out file)
>  ..and so on...
>
> In my opinion, with this approach you will be able to write good test
> cases. Just think on the line above mentioned 3 steps.
> You may come with different test cases, but your test cases will also
> ensure that application is working fine in most of the cases. :)
>
>
> Any suggestions on above approach?
>
> --
> 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/-/POcIPzZSlbYJ.
>
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: an array question

2011-08-14 Thread Kunal Patil
What about the case 1, 90 ?
It will give 190 as the answer, isn't it?
Or am I getting your algo wrong?

On Sun, Aug 14, 2011 at 11:56 PM, Dipankar Patro wrote:

> Ankur, I agree with your algo.
>
> -> radix sort from least significant to most significant.
> -> a slight modification can be done on the appending 0 part.
> when you find the a digit is absent from the number, you leave the number.
> e.g
> 95, 87, 9, 45, 38
>
> one's place, sort: (descending)
> 9, 38, 87, 95, 45
>
> ten's place sort: (leave the number at its place if it doesn't have a ten's
> place)
> 9, 95, 87, 45, 38
>
> ^^ I think this will work for all cases. Will require extremely good use of
> pointers.
>
> On 14 August 2011 19:16, Ankur Khurana  wrote:
>
>> why will 678 come after 583 ?
>> okay ., sort from least to most significant digit. append imaginary 0's at
>> the end of the numbers with varying length to make them of same length
>>
>>
>> On Sun, Aug 14, 2011 at 5:54 PM, Puneet Gautam 
>> wrote:
>>
>>> @ankur: No its not radix sort...radix sort would give wrong answer
>>> when the input contains heterogeneous numbered digits in the
>>> array(even when going 4m msd to lsd)...
>>> eg:
>>> 32,583,678,1,45,9
>>>
>>> Radix sort would give:
>>> 9,583,678,45,32,1
>>>
>>> whereas the answer has to be:
>>>
>>> 9,678,543,45,32,1
>>> and hence largest no created is 967854345321
>>>
>>> I think thats the way radix sort will work...
>>>
>>> Correct me if i m wrong...!
>>>
>>>
>>> On 8/14/11, Ankur Khurana  wrote:
>>> > isn't it a simple question of applying radix sort from most significant
>>> to
>>> > least signigicant digit and concatenating all the sorted numbers to get
>>> the
>>> > largest number..
>>> >
>>> > On Sat, Aug 13, 2011 at 11:13 PM, Kunal Patil 
>>> wrote:
>>> >
>>> >> Let me clarify.
>>> >>
>>> >> Lets take example
>>> >> 53
>>> >> 147
>>> >> 1471470
>>> >>
>>> >> As per algo:
>>> >> sort "5353535" , "1471471" and "1471470" lexicographically to get
>>> answer.
>>> >> But You are not going to compare all these simultaneously.
>>> >> Might be you will first compare 53 and 147 for lexicographical order.
>>> In
>>> >> this case you are not required  to calculate till max length.
>>> >> In fact while comparing two strings you will require only till
>>> (max(len1,
>>> >> len2)).
>>> >> (verify it !!)
>>> >> Comparing 53 and 1471470 doesn't even require till max length.
>>> >> Comparing 147 and 1471470 (co-incidentally) requires till max length.
>>> >> (worst case !)
>>> >>
>>> >>
>>> >> Consider you have only 2 strings.
>>> >> Then above code gives lexicographically largest of these two
>>> >> (This comparison is considering circular appending).
>>> >> You can now use this comparator function as parameter for sort()
>>> function
>>> >> in c++.
>>> >> So given set of strings as the input and this comparator function it
>>> will
>>> >> sort as per given criteria.
>>> >>
>>> >> I mentioned "you have to append circularly till largest of all string
>>> >> length" only for illustration purpose and to make understanding
>>> easier.
>>> >> Had I mentioned go on comparing each of 2 strings till max(len1,len2),
>>> It
>>> >> might not be grasped quickly.
>>> >> As you can see you will not always require string upto largest length
>>> to
>>> >> determine lexicographical order of 2 strings.
>>> >>
>>> >> I am bad at explaining things. So let me know whether this solved your
>>> >> doubt.
>>> >>
>>> >>
>>> >>
>>> >> On Sat, Aug 13, 2011 at 10:35 PM, aditi garg
>>> >> wrote:
>>> >>
>>> >>> @ kunal : arent we supposed to construct the string fr each number
>>> equal
>>> >>> to the max length of any number...
>>> >>> whr r v doing dat chking in dis algo?
>>> >>>
>>> >&g

Re: [algogeeks] Re: How to solve this problem

2011-08-14 Thread Kunal Patil
Yes..i agree with Dave..Here is what i think.
As you have integers upto n^3 in your input, it would need [3*lg(n) + 1]
bits to represent each integer.
So take each group of r = ceil(lg(n)) bits at a time.
So this becomes number of bits needed to represent single digit.
Each digit thus can take 2^r values.
If you use counting sort to sort digits, it will take O(n+ 2^r ) time.

You have 3 such groups.
So 3 passes needed to sort whole input set.

Overall complexity is 3*O(n+2^r)

Correct me if i am wrong anywhere in the analysis.

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: an array question

2011-08-13 Thread Kunal Patil
Let me clarify.

Lets take example
53
147
1471470

As per algo:
sort "5353535" , "1471471" and "1471470" lexicographically to get answer.
But You are not going to compare all these simultaneously.
Might be you will first compare 53 and 147 for lexicographical order. In
this case you are not required  to calculate till max length.
In fact while comparing two strings you will require only till (max(len1,
len2)).
(verify it !!)
Comparing 53 and 1471470 doesn't even require till max length.
Comparing 147 and 1471470 (co-incidentally) requires till max length. (worst
case !)


Consider you have only 2 strings.
Then above code gives lexicographically largest of these two
(This comparison is considering circular appending).
You can now use this comparator function as parameter for sort() function in
c++.
So given set of strings as the input and this comparator function it will
sort as per given criteria.

I mentioned "you have to append circularly till largest of all string
length" only for illustration purpose and to make understanding easier.
Had I mentioned go on comparing each of 2 strings till max(len1,len2), It
might not be grasped quickly.
As you can see you will not always require string upto largest length to
determine lexicographical order of 2 strings.

I am bad at explaining things. So let me know whether this solved your
doubt.


On Sat, Aug 13, 2011 at 10:35 PM, aditi garg wrote:

> @ kunal : arent we supposed to construct the string fr each number equal to
> the max length of any number...
> whr r v doing dat chking in dis algo?
>
>
> On Sat, Aug 13, 2011 at 10:25 PM, Kunal Patil  wrote:
>
>> I dont know whether this is best approach to do step 2 or not. But it's
>> certainly good.
>>
>>
>> //I will show for two strings s1 and s2
>>
>> len1 = s1.length();
>> len2 = s2.length();
>> ind1 = 0; //Index in the first string
>> ind2 = 0; //Index in the second string
>>
>> while( ind1> function returns
>> {
>> if(ind1 == len1)  // String s1 has exhausted, so start over it
>> ind1 = 0;
>>
>> if(ind2 == len2)  // String s2 has exhausted, so start over it
>> ind2 = 0;
>>
>> for(; ind1 < len1 && ind2 > // Go on comparing until any of the string exhausts or function returns
>> {
>> if( s1[ind1] == s2[ind2] ) //Same current char in both string so we need
>> to match more char
>> continue;
>> else // mismatch
>> return (s1[ind1] > s2 [ind2] );
>> }
>> }
>>
>> if (ind1==len1 && ind2==len2) // same strings
>> return true;
>>
>> //If I missed anything in the code, let me know
>>
>>
>> On Sat, Aug 13, 2011 at 9:29 PM, aditi garg wrote:
>>
>>> @kunal: what is the best way to implement step 2?
>>>
>>>
>>> On Sat, Aug 13, 2011 at 7:33 PM, Ashish Sachdeva <
>>> ashish.asachd...@gmail.com> wrote:
>>>
>>>> @kunal: seems fine.. tried it on some cases...
>>>>
>>>>
>>>> On Sat, Aug 13, 2011 at 5:17 PM, Kunal Patil wrote:
>>>>
>>>>> Following approach should work:
>>>>>
>>>>> 1)  Count max number of digit in any integer of input. Let it be m.
>>>>> (Thanks to dave..)
>>>>>
>>>>> 2) For each int having less than m digits:
>>>>>   Convert it to string of length m where you append circularly.
>>>>>   For e.g. if m=5
>>>>>53 --> 53535
>>>>>100 --> 10010
>>>>>34343 --> 34343
>>>>>8 --> 8
>>>>>
>>>>> 3) Now lexicographically sort all those strings. Apply same
>>>>> permutations to first array of integers. (again, thanx to Dave)
>>>>>
>>>>> 4) Concatenate integers of first array.
>>>>>
>>>>> For e.g.
>>>>> 8   53   147  159  1471470   71
>>>>> m=7
>>>>> corresponding string array becomes:
>>>>> "888"
>>>>> "5353535"
>>>>> "1471471"
>>>>> "1591591"
>>>>> "1471470"
>>>>> "7171717"
>>>>>
>>>>> Apply step 3. This gives int array as 8  71  53  15  147  1471470
>>>>>
>>>>> Thus, solution is 87153151471471470.
>>>>>
>>>>> Let me know about any counter-examples...
>>>>>
>>>>> You can apply tricks in programming language that will allow you to
>>>>&

Re: [algogeeks] Re: an array question

2011-08-13 Thread Kunal Patil
I dont know whether this is best approach to do step 2 or not. But it's
certainly good.


//I will show for two strings s1 and s2

len1 = s1.length();
len2 = s2.length();
ind1 = 0; //Index in the first string
ind2 = 0; //Index in the second string

while( ind1 s2 [ind2] );
}
}

if (ind1==len1 && ind2==len2) // same strings
return true;

//If I missed anything in the code, let me know


On Sat, Aug 13, 2011 at 9:29 PM, aditi garg wrote:

> @kunal: what is the best way to implement step 2?
>
>
> On Sat, Aug 13, 2011 at 7:33 PM, Ashish Sachdeva <
> ashish.asachd...@gmail.com> wrote:
>
>> @kunal: seems fine.. tried it on some cases...
>>
>>
>> On Sat, Aug 13, 2011 at 5:17 PM, Kunal Patil  wrote:
>>
>>> Following approach should work:
>>>
>>> 1)  Count max number of digit in any integer of input. Let it be m.
>>> (Thanks to dave..)
>>>
>>> 2) For each int having less than m digits:
>>>   Convert it to string of length m where you append circularly.
>>>   For e.g. if m=5
>>>53 --> 53535
>>>100 --> 10010
>>>34343 --> 34343
>>>8 --> 8
>>>
>>> 3) Now lexicographically sort all those strings. Apply same permutations
>>> to first array of integers. (again, thanx to Dave)
>>>
>>> 4) Concatenate integers of first array.
>>>
>>> For e.g.
>>> 8   53   147  159  1471470   71
>>> m=7
>>> corresponding string array becomes:
>>> "888"
>>> "5353535"
>>> "1471471"
>>> "1591591"
>>> "1471470"
>>> "7171717"
>>>
>>> Apply step 3. This gives int array as 8  71  53  15  147  1471470
>>>
>>> Thus, solution is 87153151471471470.
>>>
>>> Let me know about any counter-examples...
>>>
>>> You can apply tricks in programming language that will allow you to save
>>> actually calculating these strings.
>>> For e.g. while comparing two unequal length strings char by char if you
>>> find chars of str1 have exhausted but not of str2, you can set index in str1
>>> to start of the str1 and continue comparison.
>>>
>>>
>>> On Sat, Aug 13, 2011 at 2:06 PM, Ashish Sachdeva <
>>> ashish.asachd...@gmail.com> wrote:
>>>
>>>> @ $: how ll you manage something like this:
>>>> 2,3,100,90,10
>>>>
>>>> 2nd array becomes: 200,300,100,900,100
>>>> descendng order: 900,300,200,100,100
>>>>
>>>> how to take care which 100 is of 10 cos we need 10 1st...??
>>>> On Aug 13, 1:00 pm, rahul aravind  wrote:
>>>> > awesome alogoritm dave:):)
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > On Fri, Aug 12, 2011 at 6:48 PM, Dave 
>>>> wrote:
>>>> > > @Yasir: I think the following will work. Counterexamples welcome.
>>>> >
>>>> > > Find the number of digits in each of the integers, and find the max
>>>> of
>>>> > > that number, say m.
>>>> >
>>>> > > Fill a second array as follows: If the ith integer has m digits,
>>>> copy
>>>> > > it into the second array. If the ith number has less than m digits,
>>>> > > concatenate duplicates of the last digit of the integer to the right
>>>> > > end to expand it to m digits. Examples: m = 3, 7 goes to 777; 82
>>>> goes
>>>> > > to 822; 29 goes to 299; 0 goes to 000.
>>>> >
>>>> > > Sort the second array into descending order and carry the first
>>>> array
>>>> > > along (apply the same permutations to the first array as you do to
>>>> the
>>>> > > second).
>>>> >
>>>> > > Concatenate the integers in the first array to get the result.
>>>> >
>>>> > > Dave
>>>> >
>>>> > > On Aug 12, 7:34 am, Yasir Imteyaz  wrote:
>>>> > > > An array of integers is given and you have to find the largest
>>>> possible
>>>> > > > integer by concatenating all elements:
>>>> >
>>>> > > > example:
>>>> > > > array:  87  36  52
>>>> > > > answer:  875236
>>>> >
>>>> >

Re: [algogeeks] Re: c output doubt

2011-08-13 Thread Kunal Patil
@rohit: Cast pointer to an integer into an int to get what you are
expecting.

for e.g.

printf("%d",(int)&a[4]-(int)&a[0]);

This will give 16.

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: an array question

2011-08-13 Thread Kunal Patil
Following approach should work:

1)  Count max number of digit in any integer of input. Let it be m. (Thanks
to dave..)

2) For each int having less than m digits:
  Convert it to string of length m where you append circularly.
  For e.g. if m=5
   53 --> 53535
   100 --> 10010
   34343 --> 34343
   8 --> 8

3) Now lexicographically sort all those strings. Apply same permutations to
first array of integers. (again, thanx to Dave)

4) Concatenate integers of first array.

For e.g.
8   53   147  159  1471470   71
m=7
corresponding string array becomes:
"888"
"5353535"
"1471471"
"1591591"
"1471470"
"7171717"

Apply step 3. This gives int array as 8  71  53  15  147  1471470

Thus, solution is 87153151471471470.

Let me know about any counter-examples...

You can apply tricks in programming language that will allow you to save
actually calculating these strings.
For e.g. while comparing two unequal length strings char by char if you find
chars of str1 have exhausted but not of str2, you can set index in str1 to
start of the str1 and continue comparison.

On Sat, Aug 13, 2011 at 2:06 PM, Ashish Sachdeva  wrote:

> @ $: how ll you manage something like this:
> 2,3,100,90,10
>
> 2nd array becomes: 200,300,100,900,100
> descendng order: 900,300,200,100,100
>
> how to take care which 100 is of 10 cos we need 10 1st...??
> On Aug 13, 1:00 pm, rahul aravind  wrote:
> > awesome alogoritm dave:):)
> >
> >
> >
> >
> >
> >
> >
> > On Fri, Aug 12, 2011 at 6:48 PM, Dave  wrote:
> > > @Yasir: I think the following will work. Counterexamples welcome.
> >
> > > Find the number of digits in each of the integers, and find the max of
> > > that number, say m.
> >
> > > Fill a second array as follows: If the ith integer has m digits, copy
> > > it into the second array. If the ith number has less than m digits,
> > > concatenate duplicates of the last digit of the integer to the right
> > > end to expand it to m digits. Examples: m = 3, 7 goes to 777; 82 goes
> > > to 822; 29 goes to 299; 0 goes to 000.
> >
> > > Sort the second array into descending order and carry the first array
> > > along (apply the same permutations to the first array as you do to the
> > > second).
> >
> > > Concatenate the integers in the first array to get the result.
> >
> > > Dave
> >
> > > On Aug 12, 7:34 am, Yasir Imteyaz  wrote:
> > > > An array of integers is given and you have to find the largest
> possible
> > > > integer by concatenating all elements:
> >
> > > > example:
> > > > array:  87  36  52
> > > > answer:  875236
> >
> > > > array: 87 9 52
> > > > answer: 98752
> >
> > > --
> > > 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
> > >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: logic???????????

2011-08-13 Thread Kunal Patil
@Yasir: Yups...I also have the same algo...
Just to improvise your solution, you need not do binary search on both sides
of the pivot.
Just check End points (min-max) of the both sub-array to decide which side
to do a binary search..This works in the case of duplicate elements too.

for e.g.
2  5  8  12  45  78  91  100   101  104
k = 5
78  91  100   101  104  2  5  8  12  45
Pivot is at 2
You want to search for 12.
Check end points of both the sub-array (78,104 & 2,45)
Second range would contain 12.
So no need to call binSearch on first sub-array.

2  2  5  5  7
k = 3
So new arr is  5  7  2  2  5
Pivot is first occurrence of 2
You want to search for 5 (which is in both parts)
check end points to decide which sub-array to be searched.
While checking end-points itself you get the answer.

I hope you get it...

On Fri, Aug 12, 2011 at 11:37 PM, Yasir  wrote:

> how abt  http://ideone.com/lN2og ??
>
>
>
>
>
>  --
> 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/-/pZdvFb_t2b4J.
>
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Amazon question.

2011-08-10 Thread Kunal Patil
@Ankit: Ohh Sorry..I didnt actually read the question properly..
I didnt see we have to check for sum which must be another element in the
array & not some user provided constant value..I mis-understood it with sum
upto k problem which can be solved on sorted array in O(n)...
thats why gave a wrong comment...my Bad..

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: m'th max element

2011-08-10 Thread Kunal Patil
@Ankuj: +1 for different approach. (Though selection algo is more efficient
than this.)

On Wed, Aug 10, 2011 at 1:44 PM, nick  wrote:

> nice logic :)
>
> --
> 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/-/-rdIH5FKbk8J.
>
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Amazon question.

2011-08-10 Thread Kunal Patil
@Ankit Sambyal: Agree with ankuj...TC of your solution is O(nlogn) and not
O(n^2)...

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Directi Question

2011-08-07 Thread Kunal Patil
@Shady :
No...we can say this only at the time when following constraints are
satisfied:
1) *Outcome* of event *should be* *binary*. (In above example Sum can have
binary outcomes only i.e. EVEN or ODD)

2) Random variable x in P(x) should be supported on set {1,2,3,4,} i.e.
It *should start from 1* and then take on *contiguous values*.

3) *Sequence* *of probabilities* for x,x+1,x+2,... *must form a GP*.
   (In above sum P(1)=1/2; P(2)=1/4; P(3)=1/8 forms GP)

Taking another simple example having biased coin:
P(H) --> 1/4
P(T) --> 1 - 1/4 = 3/4.
Say we want to find out expected number of coin tosses required to get first
head.
(Outcome is binary and random variable starts from 1 & can take contiguous
values.Also, sequence of probabilities form a GP.)

You may verify that answer comes out to be 1/P(H) --> 1/(1/4) --> 4

@ never_smile: If I understand your question correctly then Probability
of getting even sum in one roll is P(2) + P(4)
For e.g. say
P(1) --> 1/5
P(2) --> 2/5
P(3) --> 1/5
P(4) --> 0
P(5) --> 1/5

P(even in one roll) --> 2/5 + 0 --> 2/5.

P(even in one roll) = 2/5;
P(even in 2 rolls) = (3/5)*(3/5);
P(even in 3 rolls)=(3/5)*(2/5)*(3/5)
This probability sequence doesn't form a GP.
Thus, above formula should not be applied & you should calculate E[x] by
trivial method.

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Directi Question

2011-08-07 Thread Kunal Patil
Probability of getting an even sum in one roll is 1/2..
Thus, expected number of rolls required to get even sum is inverse of that
i.e. 2.

Alternatively, Going by basics...

Let P(x) be probability of getting Even sum in x rolls.
P(1) = 1/2(Even)
P(2) = (1/2) * (1/2)  (Odd + Odd)
P(3) = (1/2) * (1/2) * (1/2) (Odd + Even + Odd)
P(4) = (1/2) * (1/2) * (1/2) * (1/2) (Odd + Even + Even + Odd)
& So on

Expected number is given by Summation( X*P(x) )...i.e.
1*(1/2) + 2*(1/4) + 3*(1/8) + 4*(1/16) + (theoretically infinite terms)

Let this sum be S.

Thus, S = (1/2) + (2/4) + (3/8) + (4/16) + (5/32) +

S / 2 = (1/4) + (2/8) + (3/16) + (4/32) +

S - (S/2) = (1/2) + (2-1)/4 + (3-2)/8 + (4-3)/16 + (5-4)/32 + 

Thus, S/2 = (1/2) + 1/4 + 1/8 + 1/16 + 1/32 + (theoretically infinite
terms)
R.H.S. is GP which evaluates to 1.
Thus, S = 2.
Thus, expected number of rolls required to get even sum is 2.

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] xplanation plz

2011-08-06 Thread Kunal Patil
@Saurabh: +1 for your second code.

On Sun, Aug 7, 2011 at 12:17 PM, Amol Sharma  wrote:

> nice :)
> --
>
>
> Amol Sharma
> Third Year Student
> Computer Science and Engineering
> MNNIT Allahabad
>
>
>
>
> On Sun, Aug 7, 2011 at 8:16 AM, saurabh singh  wrote:
>
>> Yup it was due to compiler optimization.check this link now,,,
>> http://ideone.com/f7keg
>>
>>
>> On Sun, Aug 7, 2011 at 8:02 AM, saurabh singh wrote:
>>
>>> The value of a has changed but it doesnt appears so...Thats bcoz the
>>> compilers are smart enough in dealing with const variables...The value has
>>> changed but doesnt appears so when you print it.
>>>
>>>
>>> On Sun, Aug 7, 2011 at 1:15 AM, Jyoti Gupta <2006gu...@gmail.com> wrote:
>>>
 but how do they both point to same address location ??


 On 7 August 2011 01:05, jagrati verma wrote:

> thanku all.
>
> On Sun, Aug 7, 2011 at 12:58 AM, Debabrata Das
>  wrote:
> > try this:
> > const int a=54;
> >int *p=(int *)&a;
> >*p=100;
> >printf("%d\n",*p);
> >printf("%x %x",p,&a);
> >
> >
> >
> > On Sun, Aug 7, 2011 at 12:28 AM, UTKARSH SRIVASTAV
> >  wrote:
> >> yes saurabh the value of a has not changed
> >>
> >> On Sat, Aug 6, 2011 at 11:20 AM, aditi garg <
> aditi.garg.6...@gmail.com>
> >> wrote:
> >>>
> >>> @saurabh
> >>> http://ideone.com/J0gNi
> >>> its jst pointing to same address bt it has not modified the
> value...chk
> >>> the abv link...
> >>> On Sat, Aug 6, 2011 at 8:13 PM, saurabh singh 
> wrote:
> 
>  http://ideone.com/Wszkg
>  On Sat, Aug 6, 2011 at 8:03 PM, jagrati verma
>   wrote:
> >
> > how can modify constant variable with the help of pointers.
> >
> > --
> > 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
> > http://groups.google.com/group/algogeeks?hl=en.
> >
> 
> 
> 
>  --
>  Saurabh Singh
>  B.Tech (Computer Science)
>  MNNIT ALLAHABAD
> 
> 
>  --
>  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
>  http://groups.google.com/group/algogeeks?hl=en.
> >>>
> >>>
> >>>
> >>> --
> >>> Aditi Garg
> >>> Undergraduate Student
> >>> Electronics & Communication Divison
> >>> NETAJI SUBHAS INSTITUTE OF TECHNOLOGY
> >>> Sector 3, Dwarka
> >>> New Delhi
> >>>
> >>> --
> >>> 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
> >>> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >>
> >>
> >> --
> >> UTKARSH SRIVASTAV
> >> CSE-3
> >> B-Tech 3rd Year
> >> @MNNIT ALLAHABAD
> >>
> >> --
> >> 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
> >> http://groups.google.com/group/algogeeks?hl=en.
> >>
> >
> > --
> > 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
> http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>


 --
 Jyoti Gupt

Re: [algogeeks] Re: latest google interview questions

2011-08-03 Thread Kunal Patil
@Shady: +1
But I cant stop laughing.[?] Hacking some1's account and doing such hilarious
posts...[?]

On Wed, Aug 3, 2011 at 9:55 PM, Anil Arya  wrote:

> @shadythank you very much
>  .Good job
>
>
> On Wed, Aug 3, 2011 at 9:48 PM, shady  wrote:
>
>> utkarsh - banned for 2 weeks.
>>
>>
>> On Wed, Aug 3, 2011 at 9:35 PM, saurabh singh wrote:
>>
>>> Abe my id was hacked ka bahana kitti baar banaega?
>>> Bas karo yaroon bahut hua.,,,apne group pe aao in log ko baksh do..
>>> *NO MORE POSTS ON THIS TOPIC.*
>>> PS:Utkarsh Srivastava is a brilliant coder and algorithimist.see his
>>> previous posts(*and an intern at Goldman Sachs*).Its just dat he had
>>> worked very hard lately.:)
>>>
>>>
>>> On Wed, Aug 3, 2011 at 9:27 PM, UTKARSH SRIVASTAV <
>>> usrivastav...@gmail.com> wrote:
>>>
 my id was hacked . i don't know anything..


 On Wed, Aug 3, 2011 at 8:49 AM, sourabh jakhar >>> > wrote:

>
> @UTKARSH STRICT ACTION WILL BE TAKEN AGAINST U IN COLLEGE FOR SPAMMING
> THE GROUp
>
> On Wed, Aug 3, 2011 at 9:16 PM, rahul  wrote:
>
>> Question 1:
>> why output is "hello".
>>
>> so printf is buffered function, as everyone knows who use linux/unix,
>> every process open 3 file by default, and these are STDOUT, STDIN, 
>> STDERR,
>> internally this program has STDOUT opened, and this "hello" is given to
>> buffer in kernel thru write system call, and kernel driver write this to
>> STDOUT, which is your console, that's the reason you get the output on
>> console.
>>
>> Question 2:
>> even a new born child knows.
>>
>>  On Wed, Aug 3, 2011 at 9:09 PM, D!leep Gupta <
>> dileep.smil...@gmail.com> wrote:
>>
>>> @Admin: yup, Plz ban such type of users from this group.
>>>
>>> Dileep Kumar
>>>Computer Science & Engineering
>>>
>>> --
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> SOURABH JAKHAR,(CSE)(Final year)
> ROOM NO 167 ,
> TILAK,HOSTEL
> 'MNNIT ALLAHABAD
>
>  The Law of Win says, "Let's not do it your way or my way; let's do it
> the best way."
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>



 --
 *UTKARSH SRIVASTAV
 CSE-3
 B-Tech 2nd Year
 @MNNIT ALLAHABAD*


  --
 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
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>
>>>
>>> --
>>> Saurabh Singh
>>> B.Tech (Computer Science)
>>> MNNIT ALLAHABAD
>>>
>>>
>>>  --
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Anil Kumar Arya
> B.Tech  III year
> computer science & engineering
> M.N.N.I.T Allahabad.
>
>
>  --
> 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] Amazon Question

2011-08-03 Thread Kunal Patil
Sort both the lists...
(Keep track of their original indices as we need to return to original list)

Modify the merge process of merge_sort:

// Assume size of list1 is m and that of list2 is n

curr_list1=0;curr_list2=0;curr_output=0;

while( curr_list1 < m && curr_list2 < n )
{
  If (list1[curr_list1] == list2[curr_list2] )
  {
 int temp = list1[curr_list1];
 output[curr_output++] = temp;

 //These while loops to ignore duplicates
 while( curr_list1 < m && list1[curr_list1] == temp )
 curr_list1++;

 while( curr_list2 < n && list2[curr_list2] == temp )
 curr_list2++;
  }

 else if( list1[curr_list1] < list2[curr_list2] )
  {
  curr_list1++;
  }

 else
  {
  curr_list2++;
  }
}

//Now output contains intersection of both the lists.
//Revert back to original lists.

TC: O(mlogm) + O(nlogn) + O(min (m,n) ) + O(m) + O(n)  = O(mlogm + nlogn)
SC: O(m+n) (To maintain associative array / copy of original lists) +
   O(min (m,n)) (To create output list) = O( m+n )

Correct me if I am wrong anywhere in the analysis.


On Wed, Aug 3, 2011 at 4:31 PM, ankit sambyal wrote:

> Given two lists write a function which returns a list which is the
> intersection of the two lists.the original lists should remain same.
> (Intersection - if first list is say,1,20 3,45 and second list is 3,24
> ,45,90,68 then intersection should be 3,45 )
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Goldman sachs

2011-08-03 Thread Kunal Patil
I agree with Ved that Apti of GS is really really tough and technical is
relatively easy..They ask CAT (Quant) like questions and you have to solve
them in little time too...Also there will be sectional cut-off for this
written test.
So dont be afraid if you can solve only 10-15 questions from quantitative
apti..Just make sure you attempt as much questions from both the sections as
possible.
Essay will also be there, subject of which will be provided in last 10 mins
of your apti.
In Interview, they ask C++ and DBMS questions mostly..

On Wed, Aug 3, 2011 at 2:39 PM, Ved  wrote:

> Questions were from "C" language lik Pointers and wat will b the
> output of the code , Errors etc.
> > Clearing written test is not that tough u shud manage time and solve
> technical which will b 10 ques first den try aptitude ..
> All the Best
>
> On Aug 3, 12:10 am, arvind kumar  wrote:
> > i mean..the technical written round.
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Aug 3, 2011 at 12:37 AM, arvind kumar 
> wrote:
> > > Hi
> > > thanks a lot..can u pls temme wat wer the main areas(and questions if
> > > possible) covered in the technical round?
> > > Regards
> > > Arvind
> >
> > >   On Wed, Aug 3, 2011 at 12:35 AM, Ved Garbha 
> wrote:
> >
> > >> Goldman Sachs :
> > >>   The aptitude+technical together(written test ) will b of 45 min ..
> Apti
> > >> will b tough but technical wil b C damn easy . followed by GD , and
> after
> > >> dat two technical and HR round
> >
> > >> On Tue, Aug 2, 2011 at 9:54 PM, arvind kumar  >wrote:
> >
> > >>> Hi there
> > >>> Goldman sachs is comin to our campus!!anyone has any idea about their
> > >>> interviews(technical),etc..?
> >
> > >>> --
> > >>> 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
> > >>>http://groups.google.com/group/algogeeks?hl=en.
> >
> > >> --
> > >> *Ved Garbha*
> >
> > >> --
> > >> 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
> > >>http://groups.google.com/group/algogeeks?hl=en.
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Merging K-sorted lists using Heap

2011-08-02 Thread Kunal Patil
@Kumar:Thanks for the very good question and
@Dave:Thanks for very very good solution...

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Find the number of solutions.

2011-07-28 Thread Kunal Patil
x^(x^x) - (x^x)^x = 0
Thus, x^(x^x) = (x^x)^x
Let's open it up by taking log on both sides...
(x^x)*log(x) = x* log(x^x)
(x^x)*log(x) = x*x*log(x)

If x==1 equation is satisfied as log(x) becomes 0..
so x=1 is definitely a solution. what if when x != 1
cancelling log(x) on both the sides..
x^x = x^2
Taking log on both sides..
x*log(x) = 2*log(x)
As x !=1 we can cancel log(x) on both the sides to get
x = 2 

Thus, final solution is {1,2}

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Puzzle

2011-07-28 Thread Kunal Patil
Insufficient data to calculate what you need to find out !!!

On Thu, Jul 28, 2011 at 9:39 PM, shubham  wrote:

> A man leaves his office daily at 07:00 PM. His driver arrives with the car
> from home to his office at sharp 07:00 PM. So he doesn't need to wait for
> any transport medium as soon he is free from his work. But today he finished
> his work early and left the office at 05:30 PM. As his driver was not there
> so he started moving towards his home on foot. After moving some distance he
> met the driver on the way (As the driver had no idea so he had started at
> the usual time) and took the car. When he reached his home he found that
> today he reached 20 minutes earlier than usual time. Then tell how much time
> it takes the man to reach his office on the normal day (with the car).
>
>  --
> 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/-/gn9AJcWvjuoJ.
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Facebook Interview question at NIT Warangal

2011-07-26 Thread Kunal Patil
@Ankur Garg: Nice explanation at the link given by u...

On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg  wrote:

> Check this
>
> http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html
>
>
> On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki wrote:
>
>> Here is the working code..
>>
>> #include 
>> #include 
>> int a[] = {1,2,3,4,5};
>> #define ARRLEN(a) (sizeof(a)/sizeof(a[0]))
>> void print_comb(int len)
>> {
>>int tlen = len;
>>int i, j, k;
>> int al = ARRLEN(a);
>>for (i = 0; i < al; i++) {
>>for (j=i+len-1; j>for (k = i; k < i+len-1; k++) {
>>printf("%d ", a[k]);
>>}
>>printf("%d\n", a[j]);
>> }
>>}
>> }
>>
>> int main(int argc, char *argv[])
>> {
>>int len = atoi(argv[1]);
>> print_comb(len);
>>return 0;
>> }
>>
>>
>>
>> On Tue, Jul 26, 2011 at 5:18 PM, praneethn  wrote:
>> >
>> > check this link:
>> >
>> > *http://www.stefan-pochmann.info/spots/tutorials/sets_subsets/*
>> >
>> > On Tue, Jul 26, 2011 at 11:59 AM, sumit 
>> wrote:
>> >>
>> >> Given an array of size n, print all the possible subset of array of
>> >> size k.
>> >> eg:-
>> >> input:
>> >> a[]={1,2,3,4}, k = 2
>> >> output:
>> >> 1,2
>> >> 1,3
>> >> 1,4
>> >> 2,3
>> >> 2,4
>> >> 3,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+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/algogeeks?hl=en.
>> >>
>> >
>> > --
>> > 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
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Shooters in a circle

2011-07-22 Thread Kunal Patil
@surender: I assume you want to give general solution to Josephus problem in
which we shoot every kth person...In that case formula for pos must be:
pos = ( x*k )%n + (k-1)

In current context, k=2...thus the formula which you gave also holds
true..but not when k != 2

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Coding..........

2011-07-22 Thread Kunal Patil
@Sunny: Excellent explanation (& solution) !!

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Finding the Kth Prime

2011-07-15 Thread Kunal Patil
@Antony: To post in this group..Just login to your gmail account. Compose
new mail containing your question and send it to "algogeeks@googlegroups.com
"

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Counting the ways.

2011-07-15 Thread Kunal Patil
I agree with skript: Number of ways of doing this is n!

One in the first row can be placed in n ways.
After one in first row has been placed,
we can place One in second row in n-1 ways and so on.
So total num of ways is n*(n-1)*...*1 = n!

One possible solution to this problem can be coded as follows:

Input: integer n
Output: different matrices satisfying given criteria


Create an array of integers 1 to n.

do
{
// Omega( n! )
   For (i =0 to n-1)
  // Omega(n)
print binary representation of (1 << arr[i] ) upto n bits //
Omega(n)
} while( Next_Permutation( arr, arr+n ) );

TC: Omega ( n! )  *  Omega ( n ) *  omega ( n )
SC: O(n)...( I dunno [?] whether Next_permutation uses any extra space or
what, so i am not considering it... [?]  )

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<1B2.png>><<324.png>>

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:
>
>> 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 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



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 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 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Longest substring 0's & 1's

2011-07-04 Thread Kunal Patil
@Sunny : Excellent !!! Keep posting such nice solutions !! :)

On Sat, Jul 2, 2011 at 1:47 AM, Anika Jain  wrote:

> ohh ok i got it.. thanx :)
>
>
> On Sat, Jul 2, 2011 at 12:48 AM, sunny agrawal wrote:
>
>> it is (2,4] not [2,4].
>> open interval, close interval . consider (i,j] as [i+1,j]
>>
>> because a[i] = sum of values from 0 to i
>> and a[j] = sum of values from 0 to j
>> if a[i] = a[j] then it means sum does not changes between a[i] to a[j]
>>
>> so from i+1 to j there are equal no of 1's and -1's
>> or in other words equal no of 0's and 1's
>>
>>
>> On Sat, Jul 2, 2011 at 12:42 AM, Anika Jain wrote:
>>
>>> @sunny: in a[2,4] has 2 1s and one 0 then how is it a solution? i mean i
>>> didnt get wen a[i]==a[j] then a[i,j] is a solution case..
>>>
>>> On Fri, Jul 1, 2011 at 4:13 PM, sunny agrawal 
>>> wrote:
>>>
 Take an array of size of the length of the string.
 fill the array positions with one where string contains 1, and -1 where
 it is 0

 Now for each i (1,n-1) perform the following operation
 a[i] = a[i-1] + a[i]
 now a[i] will contains sum of values from a[0] to a[i] in original
 array.

 Now only thing remains to find is two indexes in this array such that
 a[i] = a[j]
 where ever this condition is met ( i,j ] is a solution

 or if for some i a[i] = 0 in this case [0,i] will be a solution

 this can be done using hashing
 hash the values in the array of size 2*n+1. as range of values is -n to
 n and keep track of max interval.




 On Fri, Jul 1, 2011 at 3:22 PM, Anantha Krishnan <
 ananthakrishnan@gmail.com> wrote:

> Given a string containing 0's and 1's. One would need to find the
> longest sub-string such that the count of 0's is equal to the count of 1's
> in the largest sub string.
>
> Regards
> Anantha Krishnan
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>



 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee


  --
 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
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>  --
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> Sunny Aggrawal
>> B-Tech IV year,CSI
>> Indian Institute Of Technology,Roorkee
>>
>>  --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Implementing QUEUE with Singly link list

2011-07-04 Thread Kunal Patil
@Sandeep: Without storing explicit pointer to last element, how would you be
able to access last element in a  Singly Linked List in O(1) ??? Is there
any parallel data structure that needs to be maintained ?? and if it is
larger than size of 2 explicit pointers to last and first elements then 2
pointer strategy is obviously better !!

On Tue, Jul 5, 2011 at 10:11 AM, Sandeep Jain  wrote:

> Its the queue in which you want to add a an element.
> Small correction in the enqueue signature.
>
> void enqueue(NODEPTR &q, int data) // made it a reference, I missed it
>
> And the usage would be something like
> NODEPTR myQueue = NULL;
>
> enqueue(myQueue, 10);
> enqueue(myQueue, 20);
>
> cout<
>
>
> Regards,
> Sandeep Jain
>
>
>
>
>
> On Tue, Jul 5, 2011 at 8:30 AM, vaibhav agarwal <
> vibhu.bitspil...@gmail.com> wrote:
>
>> @sandeep what is ptr q in case of enqueue?
>>
>>
>> On Mon, Jul 4, 2011 at 12:53 PM, Sandeep Jain wrote:
>>
>>> How bout I say, the insertion and deletion functions have the following
>>> prototype?
>>>
>>>  void enqueue(NODEPTR q, int data)
>>> int deque(NODEPTR q)
>>>
>>> You are not allowed to maintain two pointers, i.e. no front and no rare
>>> pointers...
>>>
>>>
>>> Regards,
>>> Sandeep Jain
>>> Member of Technical Staff, Adobe Systems, India
>>>
>>>
>>>
>>>
>>> On Mon, Jul 4, 2011 at 10:20 PM, surender sanke wrote:
>>>
 always maintain front and rear pointers, updating them accordingly
 during insertion and deletion can achieve this in O(1)

 surender


 On Mon, Jul 4, 2011 at 9:59 PM, vaibhav shukla >>> > wrote:

> How to implement a QUEUE using a singly link list such that the
> operations ENQUEUE and DEQUEUE takes O(1) time ?
>
> --
>   best wishes!!
> Vaibhav Shukla
>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

  --
 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
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>  --
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Print 1 to n without loops

2011-06-13 Thread Kunal Patil
@Divye Kapoor : It was interesting...use of inheritance concept to print
that...
On Mon, Jun 13, 2011 at 12:09 AM, Divye Kapoor wrote:

> This will probably be the best solution yet ;)
>
> Compile time template metaprogramming:
>
> template
> class X : public X {
> public:
>   X() { cout << N << endl; }
> };
>
> template<>
> class X<0> {
> };
>
> int main() {
>   X<100> obj;
>   return 0;
> }
>
> I know atleast 6 other ways of achieving this besides the ones
> mentioned in this thread post. :)
> How many can you come up with?
>
> On Jun 11, 8:38 pm, "/\\/a|-|a/\\/t"  wrote:
> > use goto
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Sat, Jun 11, 2011 at 8:55 PM, hary rathor 
> wrote:
> > > int main()
> > > {
> > > static int i=1;
> > > int n=100;
> > > if(i<=n)
> > > {
> > > printf("%d ",i);
> > > i++;
> > > main();
> > > }
> > > return 0;
> > > }
> >
> > > --
> > > 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
> > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > --
> > regards
> > /\/a|-|a/\/t
> > undergraduate computer science and engineering
> > mnnit allahabad
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] [brain teaser ] Probability Riddle Loaded Revolver 13 june

2011-06-13 Thread Kunal Patil
Assuming everything is unbiased:
probability of the next slot to contain a bullet (given, first was empty)
would be (1/4) = 0.25
After spinning:  prob(bullet) = (2/6) = 0.334...
We want to minimize the probability...
thus answer should be just to pull the trigger again..


On Mon, Jun 13, 2011 at 1:40 PM, Piyush Sinha wrote:

> ignore the above answerit shouldn't rotate again...
>
>
> On Mon, Jun 13, 2011 at 1:37 PM, Piyush Sinha wrote:
>
>>
>> should rotate again..
>>
>>
>> On Mon, Jun 13, 2011 at 1:12 PM, sunny agrawal 
>> wrote:
>>
>>> Pull the Trigger Again ??
>>>
>>>
>>> On Mon, Jun 13, 2011 at 1:01 PM, Lavesh Rawat wrote:
>>>

 *Probability Riddle Loaded Revolver  - 13* June
   *
 * ** **
 **
 *Henry has been caught stealing cattle, and is brought into town for
 justice. The judge is his ex-wife Gretchen, who wants to show him some
 sympathy, but the law clearly calls for two shots to be taken at Henry from
 close range. To make things a little better for Henry, Gretchen tells him
 she will place two bullets into a six-chambered revolver in successive
 order. She will spin the chamber, close it, and take one shot. If Henry is
 still alive, she will then either take another shot, or spin the chamber
 again before shooting.

 Henry is a bit incredulous that his own ex-wife would carry out the
 punishment, and a bit sad that she was always such a rule follower. He
 steels himself as Gretchen loads the chambers, spins the revolver, and 
 pulls
 the trigger. Whew! It was blank. Then Gretchen asks, 'Do you want me to 
 pull
 the trigger again, or should I spin the chamber a second time before 
 pulling
 the trigger?'

 What should Henry choose?
 *

 *Update Your Answers at* : Click 
 Here


 Solution:
 Will be updated after 1 day




 --

 "Never explain yourself. Your friends don’t need it
 and your enemies won’t believe it" .

 --
 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
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>
>>>
>>> --
>>> Sunny Aggrawal
>>> B-Tech IV year,CSI
>>> Indian Institute Of Technology,Roorkee
>>>
>>>
>>> --
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> *Piyush Sinha*
>> *IIIT, Allahabad*
>> *+91-8792136657*
>> *+91-7483122727*
>> *https://www.facebook.com/profile.php?id=10655377926 *
>>
>>
>
>
> --
> *Piyush Sinha*
> *IIIT, Allahabad*
> *+91-8792136657*
> *+91-7483122727*
> *https://www.facebook.com/profile.php?id=10655377926 *
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Swapping two variables without using a temporary variable

2011-06-11 Thread Kunal Patil
@KK: Why would XOR method fail when we pass same values of a & b ??

x = 6
y = 6

x = x ^ y; // x  ==>  0
y = x ^ y //  y  ==>  0 ^ 6  ==> 6
x = x ^ y //  x  ==> 6 ^ 0 ==> 6

So after XORing values of X and Y have been swapped as it is the case
normally.

On Sat, Jun 11, 2011 at 11:39 PM, KK  wrote:

> It wont give correct answer when u pass same values of a and b and
> such conditions arises in sorting
>
>
> --
> ***
> Kunal Kapadia
> Computer Science and Engineering
> B.Tech 2nd yr
> NIT Trichy
> ***
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: MS Interview

2011-06-10 Thread Kunal Patil
@ Dumanshu:
With memory restriction also XOR method works.. :)
In this case difference is just that you will be working with 400/ X
number of files..where X is size of the RAM...just maintain a variable
Curr_XOR_value and go on XORing it with element read from the file.
When you are done with reading all those numbers from "400/ X"
files..
(Curr_XOR_value) * XOR*  (expected_XOR_value for 1 to 400) ...
will give missing number...

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Puzzle

2011-06-10 Thread Kunal Patil
@ross: seems logically correct..nice solution..

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Reverse the bits.

2011-06-10 Thread Kunal Patil
How about this???
*
unsigned int flip_j_to_k_bits (unsigned int n,unsigned int j,unsigned int k)
{
 unsigned int temp;
 int num_of_on_bits = k-j+1;

 temp = (1< wrote:

> How do you reverse the bits between j to k in a 32 bit integer.
>
> For e.g.:
>
> n = 11100011;  j = 2 and k =  5
> output: 1101  (bits from 2 to 5 are reversed.)
>
> n = 11010110; j = 1 and k = 5
> output: 11101000
>
> O(1) method is preferred.
> Thanks,
> --
> Dinesh Bansal
> The Law of Win says, "Let's not do it your way or my way; let's do it
> the best way."
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Print 1 to n without loops

2011-06-10 Thread Kunal Patil
IF allowed ???
If yes...Use recursion..

On Fri, Jun 10, 2011 at 9:12 PM, Navneet Gupta wrote:

> Take n from user and print 1 to n. No loops like for/while/do-while are
> allowed to use.
>
> --Navneet
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] write an algo that deletes all negative integers without changing the order of remaining elements of the queue

2011-06-10 Thread Kunal Patil
Yups...that seems best.. :)

On Fri, Jun 10, 2011 at 4:03 PM, sunny agrawal wrote:

> initialy cal size of queue then apply a for loop
>
>
> On Fri, Jun 10, 2011 at 4:00 PM, sunny agrawal wrote:
>
>> First algorithm taht comes in mind
>>
>> deque a element
>> if +ve enque again
>> if(-ve) do nothing
>>
>> now question is terminating condition
>>
>>
>> On Fri, Jun 10, 2011 at 3:44 PM, Sangeeta wrote:
>>
>>> write an algo that deletes all negative integers without changing the
>>> order of remaining elements of the queue
>>>
>>> --
>>> 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
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>>
>>
>>
>> --
>> Sunny Aggrawal
>> B-Tech IV year,CSI
>> Indian Institute Of Technology,Roorkee
>>
>>
>
>
> --
> Sunny Aggrawal
> B-Tech IV year,CSI
> Indian Institute Of Technology,Roorkee
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] [brain teaser ] Find The Next Number 6 june

2011-06-08 Thread Kunal Patil
Ohh...that was a hard one...[?]

On Tue, Jun 7, 2011 at 10:30 AM, shashankreddy509 <
shashankreddy...@gmail.com> wrote:

> http://mathworld.wolfram.com/TwinPrimes.html
>
> 
> have look at this link...
>
> --
> 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/-/NFpFVE1lTzVfVVVK.
>
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<344.gif>>

Re: [algogeeks] Re: get rid of sohail panzer spam

2011-06-08 Thread Kunal Patil
Automatic deletion will solve the trouble only for you not for the group as
such messages are not reported spam.. [?]
What i do is: When i login just type in search box 'panzer'...mark
all...report spam and then delete from spam box..That way they are
definitely reported as spams..[?]
We can't create filter to report a message directly as a spam..[?][?]

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<33A.gif>><<323.gif>><<360.gif>>

Re: [algogeeks] Stack and Permutation Problem

2011-06-05 Thread Kunal Patil
Manually calculated it to be 14.. [?]
Can't think of any general formula but i think a formula or at least
recursive function must be there to solve this.

On Sat, Jun 4, 2011 at 1:01 PM, siva viknesh  wrote:

> Stack A has the entries a,b,c ( with a on the TOp) Stack B is empty.
> an entry pooped out of the stack A can be printed immediatly or pushed
> to stack B. An Entry popped out of the stack B can only be printed. In
> this Arrangement ,if Stack A has 4 entries, then number of possible
> permutation will be
>
> (a) 24 (b) 12 (c) 21 (d) 14
>
>
> for 3 entries ..solution is 5.abc,cba,bac,bca,acb(except
> cab)..its like 3! - 1 (n! - 1 for n=3)
>
> ..is there any easy way to find for 4 entries ???...also what is the
> general solution ??
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<330.gif>>

Re: [algogeeks] Microsoft ques : reverse of dutch national flag problem

2011-06-05 Thread Kunal Patil
Simple solution of order O(n^2), similar to bubble_sort, is obvious...
Any improvements ???

On Sun, Jun 5, 2011 at 7:03 PM, Arunachala Karthik <
arunachalakart...@gmail.com> wrote:

>
> What is the order of time specified in the question?
>
> On Thu, Jun 2, 2011 at 5:03 PM, siva viknesh wrote:
>
>>
>> In a given array of elements like [a1, a2, a3, a4, . an, b1, b2, b3,
>> b4, ... bn, c1, c2, c3, c4,  cn]
>>
>> without taking a extra memory how to merge like [a1, b1, c1, a2, b2, c2,
>> a3, b3, c3,  an, bn, cn] ..???
>>
>>
>>
>>
>> --
>> Regards,
>> $iva
>>
>>  --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] [brain teaser ] Mystery Puzzle Sherlock Holmes 26 may

2011-06-03 Thread Kunal Patil
Hahaha..nice one.. :) :)

On Thu, May 26, 2011 at 9:43 PM, DeVaNsH gUpTa wrote:

> Mark as it reads ?(Question Mark) Crimson.
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks]

2011-06-03 Thread Kunal Patil
Go to hell u spammer..[?]

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<320.gif>>

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]) {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 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 B: 0 1.5 4 5 9
>>
>> Output:
>> A can contain any combination of nos 0,1,1.5
>> and B should contain 2 3 4 5 9 (in any order.)
>>
>> Constraints: No extra space. Linear Time preferred
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] remove duplicate chars in a string without using extra memory

2011-06-03 Thread Kunal Patil
If you are not going to allow  extra space, you have to compromise on time
complexity..[?]
If you dont have your string already stored in a trie/hashmap usage of it
requires additional buffer.
Simple solution would be:
Sort given string using in-place sorting algorithm and then removal of
duplicate characters becomes O(n).
Total time complexity - O(nlogn) where n --> number of characters in the
input string.

On Thu, Jun 2, 2011 at 11:17 PM, Aakash Johari wrote:

> It was given that one or two extra variables are allowed. So I used a
> variable instead for mapping.
> It is simply mapping of each character in alphabet to a bit in the
> variable.
>
>
> On Thu, Jun 2, 2011 at 7:10 AM, Ashish Goel  wrote:
>
>> using bitmap, but  extra memory not allowed?
>>
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>>
>> On Thu, Jun 2, 2011 at 7:38 PM, Ashish Goel  wrote:
>>
>>> what is the logic, kindly explain
>>> Best Regards
>>> Ashish Goel
>>> "Think positive and find fuel in failure"
>>> +919985813081
>>> +919966006652
>>>
>>>
>>>
>>> On Sat, May 28, 2011 at 12:23 PM, Aakash Johari 
>>> wrote:
>>>
 Following code works for [A-Za-z], can be extended for whole
 character-set :

> #include 
>
> int main()
> {
> unsigned long long int a = 0;
> char str[50];
> int i;
>
> scanf ("%s", str);
>
> for ( i = 0; str[i]; i++ ) {
> if ( str[i] >= 'A' && str[i] <= 'Z' ) {
> if ( (a & (1ULL << (str[i] - 'A'))) == 0 ) {
> a |= (1ULL << (str[i] - 'A'));
> putchar (str[i]);
> }
> } else if ( str[i] >= 'a' && str[i] <= 'z' ) {
> if ( (a & (1ULL << (str[i] - 'a' + 26))) == 0 ) {
> a |= (1ULL << (str[i] - 'a' + 26));
> putchar(str[i]);
> }
> }
> }
>
> return 0;
> }
>
>
>
 On Fri, May 27, 2011 at 11:15 PM, saurabh singh >>> > wrote:

> string getStringWithoutDuplicateChars(string input)
> {
>
> create_empty_trie_ds (say trie)
>
> integer count = 0;
>
> for_each_char_in_string (say ch)
> {
>
> if(trie->contains(ch)) //if ch not there in ds then add it and
> return false otherwise return true
> {
>  input.remove(count)
>  }
>
>count++
> }
>
> return input
> }
>
> On Sat, May 28, 2011 at 11:32 AM, Rajeev Kumar <
> rajeevprasa...@gmail.com> wrote:
>
>> Design an algorithm and write code to remove the duplicate characters
>> in a string without using any additional buffer.
>>  NOTE: One or two additional variables are fine.
>>  An extra copy of the array is not.
>>
>>
>> --
>> Thank You
>> Rajeev Kumar
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Thanks & Regards,
> Saurabh
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>



 --
 -Aakash Johari
 (IIIT Allahabad)





  --
 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
 http://groups.google.com/group/algogeeks?hl=en.

>>>
>>>
>>  --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> -Aakash Johari
> (IIIT Allahabad)
>
>
>
>
>  --
> 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 option

Re: [algogeeks] MS Question

2011-06-01 Thread Kunal Patil
@Gaurav: You might want to say circular doubly linked list, didn't you ?
coz without that, its not possible to reach last node if we are at first
node or vice-versa.

On Thu, Jun 2, 2011 at 9:31 AM, Gaurav Aggarwal <0007gau...@gmail.com>wrote:

> other solution might be to use doubly linked list, even if one pointer gets
> corrupt, there is other path to reach the destination.
>
>
> On Wed, Jun 1, 2011 at 1:24 PM, Ashish Goel  wrote:
>
>> given a single linked list, there is a possibility of pointer corruption,
>> modify the data structure to ensure that the data is not lost.
>>
>> in my view a skip list is a good option, any other solutions?
>>
>> Best Regards
>> Ashish Goel
>> "Think positive and find fuel in failure"
>> +919985813081
>> +919966006652
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Gaurav Aggarwal
> SCJP
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks]

2011-05-24 Thread Kunal Patil
@Piyush:
I don't think 1010 (and any even number) will be a binary palindrome (Unless
u allow single leading zero)...(Either you allow all or allow none)
If its not so what about 1001 then ? Whether it will be a palindrome or not
?[?]

Don't you think, it isn't possible to do this in less than O(n) as we have
to look at each bit at least once to confirm that given binary number is
palindrome ?
If O(n) is permitted then Logic used in immanuel's solution looks correct to
me..

Any1 having other logic which may have less comparisons ??

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<363.gif>>

[algogeeks] 3 in 1 remote control

2011-05-21 Thread Kunal Patil
Not strictly an algorithmic question, rather a test-of-design-skills type of
question.
You are asked to design a 3-in-1 remote control for TV, a DVD player, and a
cable box.
How will you go with design ?

In my approach it should have following buttons.

1) *Device Key* :
Will represent device being controlled
For example:
If device key is in TV mode you will be able to control
channel selection, volume, and TV functions.
Similar for DVD player and Cable box.

2) *Power Button*:
Device key will represent device to be powered ON/OFF.
Master Power button
-We can power on all devices sequentially using special pressing
sequence
-or Just a single press along with Device key, in proper mode, will
do it.

3) Channel *selection buttons (0 to 9), volume + - buttons, menu button*:
These will be same for all devices.

4) *Exclusive buttons*:
These are special buttons that apply to particular device only.
  (might be recording button, rewind button, repeat button, etc.)

Any other things you can expect in this design ?
or anything related to the topic that you want to share ?

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



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] [brain teaser ] Greater than God Riddle 18 may

2011-05-18 Thread Kunal Patil
Hahaha...Nice answer Piyush !

On Wed, May 18, 2011 at 12:44 PM, Piyush Sinha wrote:

> *NOTHING*.
>
> *Greater than GOD - NOTHING*
> *Worse than EVIL - NOTHING*
> *Poor have it and rich want it - NOTHING*
> *if you eat it, you die - NOTHING
> *
> On Wed, May 18, 2011 at 12:35 PM, Lavesh Rawat wrote:
>
>>Greater than God Riddle 18 MAY PUZZLE
>>
>> *What is Greater than God, worse than evil, the poor have it, the rich
>> require it, and if you eat it, you die?*
>> *
>> *
>>
>> *Update Your Answers at* : Click 
>> Here
>>
>>
>> Solution:
>> Will be updated after 1 day
>>
>>
>>
>>
>> --
>>
>> "Never explain yourself. Your friends don’t need it
>> and your enemies won’t believe it" .
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> *Piyush Sinha*
> *IIIT, Allahabad*
> *+91-8792136657*
> *+91-7483122727*
> *https://www.facebook.com/profile.php?id=10655377926 *
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



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 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 
http://groups.google.com/group/algogeeks?hl=en.

<<35F.gif>><<33A.gif>><<320.gif>>

Re: [algogeeks] Re: nearest neighbour

2011-05-17 Thread Kunal Patil
Nice explanation Dave..Thnx for the extra info !!

On Tue, May 17, 2011 at 11:00 AM, Piyush Sinha wrote:

> thanks Dave :)
> This is a standard Google question
>
> On 5/17/11, Dave  wrote:
> > @Piyush. The simplest algorithm is to sort the array entries by the
> > number. Then the three friends of each person will be the closest
> > three of the set comprising the closest three on the left and the
> > closest three on the right. This algorithm has running time O(n log
> > n).
> >
> > Usually, we regard "being a friend" as a transitive relationship: if A
> > is a friend of B, then B also is a friend of A. However, the
> > definition of friend in this problem is non-transitive. Consider {A:1,
> > B:5, C:6, D:7, E:8} Then B, C, and D are friends of A, but A is not a
> > friend of any of them.
> >
> > Dave
> >
> > On May 16, 4:31 pm, Piyush Sinha  wrote:
> >> Say you have an array containing information regarding n people. Each
> >> person is
> >> described using a string (their name) and a number (their position
> >> along a number
> >> line). Each person has three friends, which are the three people whose
> >> number is
> >> nearest their own. Describe an algorithm to identify each person's
> >> three friends.
> >> --
> >> *Piyush Sinha*
> >> *IIIT, Allahabad*
> >> *+91-8792136657*
> >> *+91-7483122727*
> >> *https://www.facebook.com/profile.php?id=10655377926*
> >
> > --
> > 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
> > http://groups.google.com/group/algogeeks?hl=en.
> >
> >
>
>
> --
> *Piyush Sinha*
> *IIIT, Allahabad*
> *+91-8792136657*
> *+91-7483122727*
> *https://www.facebook.com/profile.php?id=10655377926 *
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



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 the given elements.

Algorithm:
*1) Initially, make START point to zeroth element and END pointing to last
element of the array.
2) Calculate max1 as:
2a) Compare arr[**START**] and arr[**END**].
   If arr[**START**] < arr[**END**]
  {
 max1 = **END** - **START**;
 Jump to 3rd step
  }
2b) If arr[**START**] >= arr[**END**]
   {
 **END**-- ;
 jump to step 2a and repeat this procedure till **
END** != **START*
*   }
3) Reset **END** so that it points to last element of the array.
4) Calculate max2 as:
4a) Compare arr[**START**] and arr[**END**].
   If arr[**START**] < arr[**END**]
  {
 max2 = **END** - **START**;
 Jump to 5th step
  }
4b) If arr**[START**] >= arr[**END**]
   {
**START**++ ;
 jump to step 4a and repeat this procedure till **
START** != **END*
*}
5) Return max( max1, max2)*

Hope this algo is clear.
This algo makes two passes over the array. Thus it is O(2n) = O(n)..[?]
Let me know if this algo fails for any case you can think of..[?]

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<363.gif>><<361.gif>><<33D.gif>><<322.gif>><<360.gif>>

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 you still have the doubt let me know.
Here is code for you:

#include#define MAX_SIZE 10
int maxinterval(int a[],int size){
int curr_max=1, prev_max=1;

for(int k=0;k prev_max)
  {
prev_max=curr_max;
  }
}
else
  curr_max=1;
}
return prev_max;}
int main(){
int arr[MAX_SIZE] = {19,18,17,21,22,23,24};
printf("%d\n",maxinterval(arr,7) );
getchar();}

As expected it gives output 5.

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



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 to size-2
   if next element of array is greater than current element
 {
  increment curr_max;
  check whether curr_max is greater than prev_max, if yes,
assign   curr_max to prev_max;
 }
   else // next element is smaller than or equal to current element
 reset curr_max to 1;
//End for

Finally return prev_max*

This is clearly O(n) as it iterates through array only once.

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Puzzle

2011-05-14 Thread Kunal Patil
Each team plays a total of 14 matches. Top 50% teams(4 out of 8) qualify for
the semis.
Thus, u must win more than 50% matches to be sure to get into semis. Thus, 8
is the answer.

On Fri, May 13, 2011 at 12:14 AM, amit  wrote:

> Consider a series in which 8 teams are participating. each team plays
> twice with all other teams. 4 of them will go to the semi final.How
> many matches should a team win, so that it will ensure that it will go
> to semi finals.?
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: FUN TEASER 11 may

2011-05-12 Thread Kunal Patil
@ Anil: +1 dude...Nice answer...

On Wed, May 11, 2011 at 8:52 PM, anil chopra wrote:

> i will stop imaging.
>
>
> On Wed, May 11, 2011 at 7:38 PM, Dave  wrote:
>
>> I was on a river boat in Europe, and the emergency drill was to go to
>> the upper deck and wait, high and dry, for the boat to sink into the
>> muddy river bottom.
>>
>> Dave
>>
>> On May 11, 2:09 am, Lavesh Rawat  wrote:
>> > *FUN TEASER
>> >  *
>> > *
>> > *
>> > **
>> > *Imagine you are alone in a boat in the middle of a river. Suddenly the
>> boat
>> > starts to sink. You don't know swimming and no one is around to help
>> you.
>> > How do you get out of the situation?
>> > *
>> >
>> > *Update Your Answers at* : Click
>> > Here<
>> http://dailybrainteaser.blogspot.com/2011/05/fun-teaser-11-may.html?l...>
>> >
>> > Solution:
>> > Will be updated after 1 day
>> >
>> > --
>> >
>> > "Never explain yourself. Your friends don’t need it
>> and
>> > your enemies won’t believe it" .
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Candy_splitting in GCJ

2011-05-08 Thread Kunal Patil
OMG !!! Was it so easy
I feel lyk crying that i didnt think of this...Really bad of mine.. [?][?]

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.

<<33A.gif>><<33F.gif>>

[algogeeks] Candy_splitting in GCJ

2011-05-08 Thread Kunal Patil
Can anybody tell me How to solve candy splitting problem appeared in Google
Code Jam Qualification round?
I know there is solution, if XOR of all elements comes to be zero.
But i wasn't able to proceed from there as I couldn't think of way how to
partition that elements.
(I have read solutions from other contestants but as expected they are dirty
for the one who doesn't know logic behind program)
So plz help...

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] [brain teaser ] Short Riddle 27 april

2011-04-30 Thread Kunal Patil
Must admit it was nice !!!
Well use of English and sentence construction..

On Wed, Apr 27, 2011 at 1:59 PM, Lavesh Rawat wrote:

> * Short Riddle
>
>  *
> *How far can a dog run into the forest?
>
> *
> 
> *Update Your Answers at* : Click 
> Here
>
> Solution:
> Will be updated after 1 day
>
>
>
>
> --
>
> "Never explain yourself. Your friends don’t need it and
> your enemies won’t believe it" .
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks]

2011-04-21 Thread Kunal Patil
@Hary rathor: Your program also crash on my Dev-Cpp (Version 4.9.9.2)..Make
sure whether it runs on your PC !!
I don't know whether Literal can be type-casted...

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Sites for Interview Questions

2011-04-16 Thread Kunal Patil
geeksforgeeks.org
BTW..
Thanks for creating this post...I have came across really nice sites that
interest me in above replies..

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] ADULT SEX PHOTOS

2011-04-14 Thread Kunal Patil
@All : Please report it spam and then delete. Gmail will look into it if
reported spam by many people.

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] regarding telephonic interview at Cisco

2011-04-08 Thread Kunal Patil
Friends in my class appeared for it recently. They were asked OS n
Networking based questions.

On Thu, Apr 7, 2011 at 11:09 PM, nitish goyal wrote:

> If anyone had telephonic interview at cisco regarding summer internship,
> then
> please the experience asap. I am having this interview tomorrow.
>
> --
> Regards,
> Nitish Goyal
>
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] [brain teaser ] 30march

2011-03-31 Thread Kunal Patil
Nice to See so many Kunal here !!! :P

On Wed, Mar 30, 2011 at 11:42 PM, Kunal Yadav wrote:

> One is grandpa
> --
> Regards
> Kunal Yadav
> (http://algoritmus.in/)
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] [brain teaser ] 30march

2011-03-30 Thread Kunal Patil
Excellent answer Kunal !!

On Wed, Mar 30, 2011 at 1:55 PM, kunal srivastav  wrote:

> grandfather, father and son went for fishing... here we have two fathers
> and two sons
>
>
> On Wed, Mar 30, 2011 at 1:52 PM, Lavesh Rawat wrote:
>
>> *Fishing Problem *
>> *
>> *Two fathers and two sons went for fishing. Each of them caught a fish,
>> and none of them caught the same fish. However, they caught a total of only
>> three fish. How is this possible?
>>
>> Update Your Answers at : Click 
>> Here
>>
>> Solution:
>> Will be updated after 1 day
>>
>>
>>
>>
>>
>> --
>>
>> "Never explain yourself. Your friends don’t need it
>> and your enemies won’t believe it" .
>>
>> --
>> 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
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> thezeitgeistmovement.com
>
>  --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Check out One More Interesting & Challenging Question...Longest Consecutive Elements Sequence.

2011-03-28 Thread Kunal Patil
@Bittu:
Can you elaborate more how Constructing BST (I hope it stands for Binary
Search Tree) would be o(n)...
I think It would also be  O(nlog(n))...
My xplanation:
Single element can be inserted in BST in O(log n)
So inserting n elements would be n * O(log n) --> O(n log n) 

So as per me your solution is also not correct...
correct me if I'm wrong somewhere !!!

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Announcing ITRIX OPC 2011

2011-03-28 Thread Kunal Patil
I am able to view the solutions but not able to get the logic behind it...
Can you explain it...Or any1 who has solvd it can xplain !!
A link, if any, to an article explaining logic behind it would be awesome...
Also idea of writing an editorial explaining logic to solve problems in this
contest wont be bad !!

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Announcing ITRIX OPC 2011

2011-03-28 Thread Kunal Patil
@rk: thnx...
@raunak: https://www.spoj.pl/ITRIX11/problems/main

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Announcing ITRIX OPC 2011

2011-03-27 Thread Kunal Patil
How to solve that "Lucky Sequence Again" problem...
i tried it using vectors...for small values it succeeded..
but it wasn't calculating for 10^10 or for large condition..
So what was the logic to solve the problem ???

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Coding Round

2011-03-26 Thread Kunal Patil
Yes...Kunal is right !!!
It doesn't matter whether getMax() removes element or not, because MAX value
is maintained in each node of stack which is pointing to the maximum of the
value present below or up to that element...
So if stack is
5  3  2  8  6
Then nodes would have following structure
5 max --> 5
3 max --> 5
2 max --> 5
8 max --> 8
6 max --> 8

U shud have got it now

On Sat, Mar 26, 2011 at 4:06 PM, kunal srivastav  wrote:

> maintain a pointer to the max element so far in every element of the
> stack..
> while push - if the new element is greater than the stack->top->max then
> add the new element at the top and hence make the max pointer of the new
> element point to itself, otherwise the new element is less than the max till
> yet and hence point the max part of the new element to the max part of the
> element at the top
>
> thus at each point the max pointer of the top most element points to the
> current max of the stack
>
> pop - usual, no need to do anything :)
>
> see if you are able to follow this logic. getmax() is O(1) because you just
> need to deference the max part of the top most element at any time
>
> On Sat, Mar 26, 2011 at 3:43 PM, balaji a  wrote:
>
>> yeah it wont remove the element...GetMax() only returns the maximum
>> element added so far..
>>
>>
>> On Thu, Mar 24, 2011 at 9:42 AM, MK  wrote:
>>
>>> Actually, you probably mean that GetMax() does not remove it from the DS?
>>>
>>> Sorry for the hasty conclusion.
>>>
>>> On Thu, Mar 24, 2011 at 12:11 AM, MK  wrote:
>>> > "2) Design a DS that would do Push(),Pop(), and GetMax() elements at
>>> > complexity O(1)"
>>> >
>>> > Are you sure you remember this correctly? This would give you a way of
>>> > sorting in O(1).
>>> >
>>> > Thanks..
>>> >
>>> >
>>> >
>>> > On Thu, Mar 24, 2011 at 12:09 AM, balaji a 
>>> wrote:
>>> >> The main thing they are testing is Problem Solving and the Algorithm
>>> >> Designing ability. Coding Ability is only next. If you have good
>>> knowledge
>>> >> in Data Structures and good Problem Solving skills with coding ability
>>> you
>>> >> can easily crack through the interview. This is what i infered from my
>>> >> experience.
>>> >>
>>> >> On Thu, Mar 24, 2011 at 12:33 AM, kunal srivastav
>>> >>  wrote:
>>> >>>
>>> >>> hi people, could someone tell me in detail what all things to prepare
>>> for
>>> >>> amazon including the resources to consult for the same?? it would be
>>> really
>>> >>> helpful
>>> >>>
>>> >>> On Thu, Mar 24, 2011 at 12:11 AM, Akash Mukherjee <
>>> akash...@gmail.com>
>>> >>> wrote:
>>> 
>>>  kul man...wud appreciate if u cud post your question
>>> 
>>>  On Wed, Mar 23, 2011 at 11:28 PM, balaji a >> >
>>>  wrote:
>>> >
>>> > hi i got till the third round of technical interview out of the
>>> four
>>> > rounds and got eliminated in third round.anyways thnx for ur
>>> support
>>> > dude :-)
>>> >
>>> > On Tue, Mar 22, 2011 at 12:51 PM, balaji a <
>>> peshwa.bal...@gmail.com>
>>> > wrote:
>>> >>
>>> >> Thnx :-) I am from SSN College of Engineering,Chennai
>>> >> l
>>> >>>
>>> >>>
>>> >>
>>> >> On Tue, Mar 22, 2011 at 12:28 PM, Akash Mukherjee <
>>> akash...@gmail.com>
>>> >> wrote:
>>> >>>
>>> >>> u r welcome :), nd all the best for ur test.btw, which clg??
>>> >>>
>>> >>> On Tue, Mar 22, 2011 at 11:45 AM, guru 
>>> >>> wrote:
>>> 
>>>  Thank you very much for the info friendAnd sure will give u
>>> a
>>>  treat :-)
>>> 
>>>  On Mar 22, 11:02 am, Akash Mukherjee 
>>> wrote:
>>>  > hey, dis is what i was told by a friend working @ amazon -
>>>  >
>>>  > Sometimes they do go to the level of the subject basics like
>>> OS or
>>>  > DS but
>>>  > you should be able to tackle these if you had studied well. No
>>>  > separate prep
>>>  > is needed.
>>>  >
>>>  > Few Favs DS & Algos ( i should get treat for revealing
>>> this.;)... )
>>>  > 1) All Trees (Binary for sure)
>>>  > 2) Graphs
>>>  > 3) Sorting Algos
>>>  > 4) Heaps
>>>  > "Let us C" ... though clichéd gives a good insight. If you can
>>> find
>>>  > time.
>>>  >
>>>  > can u tell a bit more about your profile?? fresher??
>>>  >
>>>  > On Tue, Mar 22, 2011 at 11:20 AM, guru <
>>> peshwa.bal...@gmail.com>
>>>  > wrote:
>>>  > > Hi geeks,
>>>  > >tomorrow i am having Amazon.com's Coding round followed
>>> by
>>>  > > Interview...pls suggest some tips to help me out...
>>>  >
>>>  > > --
>>>  > > 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

Re: [algogeeks] Re: 23march

2011-03-23 Thread Kunal Patil
@dave:
Very nice answer yaar..Excellent !!!

On Wed, Mar 23, 2011 at 7:08 PM, Dave  wrote:

> It is LCM(2,3,4,5,6,7,8,9,10) - 1 = 2^3 * 3^2 * 5 * 7 - 1 = 2519.
>
> LCM = least common multiple.
>
> Dave
>
> On Mar 23, 2:41 am, Lavesh Rawat  wrote:
> > *A Remainder is chasing me Problem Solution*
> > *
> > *I just found a number with an interesting property:
> > When I divide it by 2, the remainder is 1.
> > When I divide it by 3, the remainder is 2.
> > When I divide it by 4, the remainder is 3.
> > When I divide it by 5, the remainder is 4.
> > When I divide it by 6, the remainder is 5.
> > When I divide it by 7, the remainder is 6.
> > When I divide it by 8, the remainder is 7.
> > When I divide it by 9, the remainder is 8.
> > When I divide it by 10, the remainder is 9.
> > It's not a small number, but it's not really big, either. When I looked
> for
> > a smaller number with this property I couldn't find one.
> > Can you find it?
> >
> > Update Your Answers at : Click
> > Here<
> http://dailybrainteaser.blogspot.com/2011/03/23march.html?lavesh=lavesh>
> >
> > Solution:
> > Will be updated after 1 day
> >
> > --
> >
> > "Never explain yourself. Your friends don’t need it
> and
> > your enemies won’t believe it" .
>
> --
> 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
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: power of 2

2011-03-20 Thread Kunal Patil
@cegprakash:
y dont u use formula...
log2(n) --> log(n) / log(2)

-- 
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 
http://groups.google.com/group/algogeeks?hl=en.



  1   2   >