[algogeeks] someone pls explain the o/p??

2012-01-29 Thread Ashish Sachdeva
http://ideone.com/Ily5v

-- 
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] Re: Concept of Pointer

2011-08-23 Thread Ashish Sachdeva
agreed... then ++ has higher precedence then *...
then answer should be BCD...

then y is it showing ACD in compiler??

On Aug 23, 7:20 pm, Akhilesh Vedhera  wrote:
> @Ashish in the first one ++ is a post increment so its associativity
> is from L->R... also acc to
>  http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
> precedence of (post inc operator) is greater than *(derefrence) so acc
> to me s++ should take place first y output is A first it should be
> 'B'
>
> On Aug 23, 7:38 am, Sanjay Rajpal  wrote:
>
>
>
>
>
>
>
> > +1 to ADITI.
>
> > Sanju
> > :)
>
> > On Mon, Aug 22, 2011 at 2:51 PM, Ashish Sachdeva 
> > > wrote:
> > > for the 1st printf i hv this explanation:
> > > precedence of ++ is greater then *   ... but associativity of both of
> > > them is right to left...
> > > thats why dereferenced takes place 1st and then the pointer is
> > > incremented...
>
> > > rest is fine...
>
> > > correct me if i m wrong...
>
> > > On Aug 22, 3:47 pm, aditi garg  wrote:
> > > > in frst printf we acess *s and s is incremented later...so it prints A 
> > > > bt
> > > at
> > > > the same time s points to B now...
> > > > In 2nd printf s is incremented frst and thn dereferencd...after
> > > incrementing
> > > > it points to C and whn we dereference it we get C
> > > > in the third printf *s=C whn we increment this we get D
> > > > so the ans wud be ACD...
> > > > I hope its  clear
>
> > >  > On Mon, Aug 22, 2011 at 4:03 PM, MANNU  wrote:
> > > > > main()
> > > > > {
> > > > > char ch[]="ABCD";
> > > > > char *s;
> > > > > s=ch;
> > > > > printf("%c",*s++);
> > > > > printf("%c",*++s);
> > > > > printf("%c",++*s);
> > > > > }
>
> > > > > Can anyone plz tell me the concept behind output??
>
> > > > > --
> > > > > 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.

-- 
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] Re: Concept of Pointer

2011-08-22 Thread Ashish Sachdeva
for the 1st printf i hv this explanation:
precedence of ++ is greater then *   ... but associativity of both of
them is right to left...
thats why dereferenced takes place 1st and then the pointer is
incremented...

rest is fine...

correct me if i m wrong...

On Aug 22, 3:47 pm, aditi garg  wrote:
> in frst printf we acess *s and s is incremented later...so it prints A bt at
> the same time s points to B now...
> In 2nd printf s is incremented frst and thn dereferencd...after incrementing
> it points to C and whn we dereference it we get C
> in the third printf *s=C whn we increment this we get D
> so the ans wud be ACD...
> I hope its  clear
>
>
>
>
>
>
>
>
>
> On Mon, Aug 22, 2011 at 4:03 PM, MANNU  wrote:
> > main()
> > {
> > char ch[]="ABCD";
> > char *s;
> > s=ch;
> > printf("%c",*s++);
> > printf("%c",*++s);
> > printf("%c",++*s);
> > }
>
> > Can anyone plz tell me the concept behind output??
>
> > --
> > 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.



Re: [algogeeks] Re: an array question

2011-08-13 Thread Ashish Sachdeva
@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
>> >
>> > > > 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.
>

-- 
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] Re: an array question

2011-08-13 Thread Ashish Sachdeva
@ $: 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.



Re: Re: [algogeeks] Re: adobe

2011-08-06 Thread Ashish Sachdeva
thanx mukul for explanation checked it randomly on 123.. it works
fine...

On Sat, Aug 6, 2011 at 11:27 PM, Ashish Sachdeva  wrote:

> mukul, pls explain my following doubts:
> 1. whats the need of subtracting the numbers, like u subtracted 91 then 52
> etc...
> 2. the ones digit 7 is ok... didnt get how did u reach 4??
>
>
> On Sat, Aug 6, 2011 at 3:22 PM, Mukul Gupta wrote:
>
>> Vaibhav,
>> Hmm, fine that. I am more interested in the 2nd approach. The first
>> approach is simple brute force.
>>
>> On Sat, Aug 6, 2011 at 3:11 PM,  wrote:
>>
>>> Mukul, in first approach instead of sending the string again and again u
>>> can use the formula
>>> (a*b)%m = ((a%m)*(b%m))%m
>>> this way u can do sumthin like dis
>>>
>>> int count = 0, a = 1;
>>> while(a != 0) {
>>> count++;
>>> a = ((a*10)%n + 1) %n;
>>> }
>>>
>>> n later output a string consisting of count one's..
>>>
>>> Regards
>>> VM
>>>
>>> 3rd Year, Computer Engineering,
>>> Netaji Subhas Institute of Technology.
>>>
>>> On , Mukul Gupta  wrote:
>>> > Manee, Nice Question.
>>> > I have thought of two algorithms. I wanted to know how one judges them.
>>> Both have similar time complexity but the 2nd one is slightly complex and
>>> much more logical.
>>> >
>>> > 1. Keeping on adding 1 as a string of 1's and apply it to this modulo
>>> function to check when it becomes 0.
>>> >
>>> >
>>> > long long modulo(char b[],long long a)
>>> > {long long d=0,len,i,j,k;
>>> > len=strlen(b);
>>> > for (k=0;k {d*=10;
>>>
>>> > d+=b[k]-48;
>>> > d=d%a;
>>> > }
>>> >
>>> > return d;
>>> >
>>> > }
>>> >
>>> >
>>> > 2. Any number ending in 3 will have the last digit as 1 if it is
>>> multiplied by 7.
>>> > Consider a case 13 ...let the required answer have 11.111. as
>>> its representation.13 x 7 = 91.
>>> > So subtracting the 3 digit of of 111.. by 91...we get
>>> 111...11020Now we know that the ones digit of the required number is
>>> 7...
>>> >
>>> > Similarly, if the last digit of a ten's digit has to be '2'...The
>>> number has to be multiplied by 4.So we subtract 13 x 4 = 52 from.
>>> > 1.02 to get 11...050...So we get the ten's digit as 4
>>> >
>>> > Similarly, now for a number to end in 5...it has to be multiplied
>>> by 5we subtract...65 from 111...105to get 111..1040...
>>> > Hundred's digit is 5
>>> > Similarly, now for a number to end in 4...it has to be multiplied
>>> by 8 ... we subtract 104 from 111...104to get 111...000. and thus we end
>>> the  process as we have got the remainder as 0.
>>> >
>>> >   Thus, our required answer is 13 x 8547 = 11
>>> >
>>> > Now I want to know...that both the methods have similar complexity ie.
>>> O(k) where k is the number of 1's. However, 2nd is much more logical and
>>> complex. What does the company look for?
>>> >
>>> > Suggest some better methods or make ammends.
>>> >
>>> > Regards,
>>> >
>>> > Mukul Gupta
>>> > 3rd Year, Computer Engineering,
>>> > Netaji Subhas Institute of Technology.
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > On Sat, Aug 6, 2011 at 9:51 AM, sahil gujral gujralsa...@gmail.com>
>>> wrote:
>>> >
>>> > yes u r wrong..1 is nt divisible by 23
>>> >
>>> >
>>> > On Sat, Aug 6, 2011 at 9:15 AM, sumit sumitispar...@gmail.com> wrote:
>>> >
>>> >
>>> > This looks quite simple.
>>> >
>>> > Every number ending in 3 follows a pattern.eg-
>>> >
>>> > 3 - 111
>>> >
>>> > 13 - 11
>>> >
>>> > 23 - 1 etc
>>> >
>>> > we can find the reauired no. by :
>>> >
>>> > suppose input no. is 33
>>> >
>>> > In every case leave the no at 1's place(least significant) i.e. 3, In
>>> >
>>> > 33 you will 

Re: Re: [algogeeks] Re: adobe

2011-08-06 Thread Ashish Sachdeva
mukul, pls explain my following doubts:
1. whats the need of subtracting the numbers, like u subtracted 91 then 52
etc...
2. the ones digit 7 is ok... didnt get how did u reach 4??

On Sat, Aug 6, 2011 at 3:22 PM, Mukul Gupta wrote:

> Vaibhav,
> Hmm, fine that. I am more interested in the 2nd approach. The first
> approach is simple brute force.
>
> On Sat, Aug 6, 2011 at 3:11 PM,  wrote:
>
>> Mukul, in first approach instead of sending the string again and again u
>> can use the formula
>> (a*b)%m = ((a%m)*(b%m))%m
>> this way u can do sumthin like dis
>>
>> int count = 0, a = 1;
>> while(a != 0) {
>> count++;
>> a = ((a*10)%n + 1) %n;
>> }
>>
>> n later output a string consisting of count one's..
>>
>> Regards
>> VM
>>
>> 3rd Year, Computer Engineering,
>> Netaji Subhas Institute of Technology.
>>
>> On , Mukul Gupta  wrote:
>> > Manee, Nice Question.
>> > I have thought of two algorithms. I wanted to know how one judges them.
>> Both have similar time complexity but the 2nd one is slightly complex and
>> much more logical.
>> >
>> > 1. Keeping on adding 1 as a string of 1's and apply it to this modulo
>> function to check when it becomes 0.
>> >
>> >
>> > long long modulo(char b[],long long a)
>> > {long long d=0,len,i,j,k;
>> > len=strlen(b);
>> > for (k=0;k {d*=10;
>>
>> > d+=b[k]-48;
>> > d=d%a;
>> > }
>> >
>> > return d;
>> >
>> > }
>> >
>> >
>> > 2. Any number ending in 3 will have the last digit as 1 if it is
>> multiplied by 7.
>> > Consider a case 13 ...let the required answer have 11.111. as
>> its representation.13 x 7 = 91.
>> > So subtracting the 3 digit of of 111.. by 91...we get
>> 111...11020Now we know that the ones digit of the required number is
>> 7...
>> >
>> > Similarly, if the last digit of a ten's digit has to be '2'...The
>> number has to be multiplied by 4.So we subtract 13 x 4 = 52 from.
>> > 1.02 to get 11...050...So we get the ten's digit as 4
>> >
>> > Similarly, now for a number to end in 5...it has to be multiplied by
>> 5we subtract...65 from 111...105to get 111..1040...
>> > Hundred's digit is 5
>> > Similarly, now for a number to end in 4...it has to be multiplied by
>> 8 ... we subtract 104 from 111...104to get 111...000. and thus we end
>> the  process as we have got the remainder as 0.
>> >
>> >   Thus, our required answer is 13 x 8547 = 11
>> >
>> > Now I want to know...that both the methods have similar complexity ie.
>> O(k) where k is the number of 1's. However, 2nd is much more logical and
>> complex. What does the company look for?
>> >
>> > Suggest some better methods or make ammends.
>> >
>> > Regards,
>> >
>> > Mukul Gupta
>> > 3rd Year, Computer Engineering,
>> > Netaji Subhas Institute of Technology.
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Sat, Aug 6, 2011 at 9:51 AM, sahil gujral gujralsa...@gmail.com>
>> wrote:
>> >
>> > yes u r wrong..1 is nt divisible by 23
>> >
>> >
>> > On Sat, Aug 6, 2011 at 9:15 AM, sumit sumitispar...@gmail.com> wrote:
>> >
>> >
>> > This looks quite simple.
>> >
>> > Every number ending in 3 follows a pattern.eg-
>> >
>> > 3 - 111
>> >
>> > 13 - 11
>> >
>> > 23 - 1 etc
>> >
>> > we can find the reauired no. by :
>> >
>> > suppose input no. is 33
>> >
>> > In every case leave the no at 1's place(least significant) i.e. 3, In
>> >
>> > 33 you will be left with 3(after removal of 3 at first place).
>> >
>> > Now ,3 *(rest of nos +1 ) is your answer (in case of 33 it is 3*(3+1)
>> >
>> > = 12 i.e  ).
>> >
>> > for 103 it is 3*(10+1) = 33 1's.
>> >
>> >
>> >
>> > Correct if I am wrong.
>> >
>> >
>> >
>> >
>> >
>> >
>> > On Aug 5, 4:33 pm, Manee mani.ma...@gmail.com> wrote:
>> >
>> > > ADOBE asks the very basic C/C++ questions
>> >
>> > >
>> >
>> > > one of their toughest however was :
>> >
>> > >
>> >
>> > > every number ending in 3 has a multiple of the form "111...111"
>> >
>> > >
>> >
>> > > e.g 3 has 111
>> >
>> > >  13 has 11
>> >
>> > > so on..
>> >
>> > >
>> >
>> > > find the algo for finding the number for an input number ending in 3.
>> >
>> > >
>> >
>> > > On Aug 5, 2:33 pm, Agyat jalsa.n.sa...@gmail.com> wrote:
>> >
>> > >
>> >
>> > >
>> >
>> > >
>> >
>> > >
>> >
>> > >
>> >
>> > >
>> >
>> > >
>> >
>> > > > hey, guys adobe is visiting our campus. So those who know questions
>> >
>> > > > that adobe asked in written or interview, please post here as it
>> will
>> >
>> > > > be of great help (as adobe has visited some colleges already).
>> >
>> > > > Thank you in advance.
>> >
>> >
>> >
>> > --
>> >
>> > 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] Re: MS [Written Question]

2011-08-03 Thread Ashish Sachdeva
@poised:
i think this:

double round(double num)
{ return (int)(num+0.5)
}

works for all...
http://www.ideone.com/WfEIw

On Aug 3, 5:45 pm, Gene  wrote:
> Your solution to 1 works fine. I hope you get the job. But it needs
> O(N) additional storage for the stack. You can also do with constant
> additional storage.
>
> #include 
> int main(void)
> {
> #define N (sizeof a / sizeof a[0])
>   int a[] = {7, 9, 4, 8, 2};
>   int result[N], i, product;
>   for (i = 0, product = 1; i < N; product *= a[i++])
>     result[i] = product;
>   for (i = N - 1, product = 1; i >= 0; product *= a[i--])
>     result[i] *= product;
>   for (i = 0; i < N; i++)  printf("%d ", result[i]);
>   printf("\n");
>   return 0;
>
> }
>
> On Aug 3, 7:08 am, Poised~  wrote:
>
>
>
>
>
>
>
> > I am not looking for answer. Just sharing these Section 2 questions:
>
> > 1. Given an array arr[] of n integers, construct a Product Array prod[] (of
> > same size) such that prod[i] is equal to the product of all the elements of
> > arr[] except arr[i]. Solve it without division operator. Give an efficient
> > code.
> > (if you are interested, here is my solution:http://ideone.com/EaTUF,
> > developed at the test time itself).

-- 
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.