Re: [algogeeks] Euler Phi Function

2011-08-30 Thread Manmeet Singh
N = p1 ^ K1  *   p2 ^ k2 ..

phi(N) = p1^(K1) * (1-1/p1) * .

phi(N) = N * (1 - 1/p1)  * (1 - 1/p2) .

phi(N) = (N - N/p1) * (1 - 1/p2)..
so now result which was initally N
now is N - N / p1
phi(N) = result * (1 - 1/p2)...
phi(N) = (result - result / p2) ...




On Tue, Aug 30, 2011 at 6:27 PM, KK kunalkapadi...@gmail.com wrote:

 This is the code for the Euler phi function:
 int phi (int n) {
int result = n;
for (int i=2; i*i=n; ++i)
if (n % i == 0) {
while (n % i == 0)
n /= i;
result -= result / i; // M NOT GETTING THIS...
}
if (n  1)
result -= result / n;
return result;
 }

 why is it subtracting result/i from result if i is a factor of n??
 plzzz 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.



-- 
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] hi

2011-08-25 Thread Manmeet Singh
@Mayank u can directly send hi to her on personal gmail. please dnt spam.
let it be algo group

On Thu, Aug 25, 2011 at 11:42 AM, mayank gaur gaur.mayank.9...@gmail.comwrote:

 hi


 On Thu, Aug 25, 2011 at 11:37 AM, S MADHU madhu.mca...@gmail.com wrote:

 hi

 --
 Regards
 MADHU.

 --
 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] latest google interview questions

2011-08-03 Thread Manmeet Singh
will all u stop all this. dont put any comments on all this now.

On Wed, Aug 3, 2011 at 11:20 PM, Anil Arya anilarya...@gmail.com wrote:


 @coder dumca--- Utkarsh --- google me nahi Goldman Sachs me  jane
 wala hai..Google ko ye saubhagya prapt nhi hoga
 On Wed, Aug 3, 2011 at 10:55 PM, coder dumca coder.du...@gmail.comwrote:

 abe tumhe to factory me data entry ki job bhi nahi milehi , bada aaya
 google me interns lene wala.


 On Tue, Aug 2, 2011 at 6:35 PM, tmdhat tmd...@gmail.com wrote:

 dude

 keep threads clean.
 and please don't feed the trolls.

 it's obviously an entire bullshit from the beginning,,,
 why feed the trolls?

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

 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



  --
 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 Interview Question

2011-08-01 Thread Manmeet Singh
Your code does not works proper;y for all cases

On Mon, Aug 1, 2011 at 10:42 PM, Rohit jalan jalanha...@gmail.com wrote:

 Here is the recursive algo:

 Rearrange(A,p,q)
 1. if p is not equal to q do the following
 2. r ← (p+q)/2
 3. Exchange A[(p+r)/2..r] ←→ A[(p+q)/2 +1 ..(r+q)/2].
 4. Rearrange(A,p,r)
 5. Rearrange(A,r+1,q)
 6. return



 On Mon, Aug 1, 2011 at 1:45 PM, Abhishek Gupta gupta.abh...@gmail.comwrote:

 A is an array of size 2n such that first n elements are integers in any
 order and last n elements are characters.
 i.e. A={i1 i2 i3 in c1 c2 c3... cn}
 then we have to rearrange the elements such that final array is
 A ={ i1 c1 i2 c2 .. in cn}


 Example :
 input : A ={ 5,1,4,d,r,a};
 output : A= {5,d,1,r,4,a};

 --
 Abhishek Gupta
 MCA
 NIT Calicut
 Kerela

  --
 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 :
 ROHIT JALAN
 B.E. Graduate,
 Computer Science Department,
 RVCE, Bangalore

  --
 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] preprocessor directive

2011-07-25 Thread Manmeet Singh
i+1 * i+1

= 2 * i + 1

for i = 3, j = 7 (2 *3 + 1)

On Mon, Jul 25, 2011 at 6:06 PM, Arshad Alam alam3...@gmail.com wrote:

 what should be the output of the following and how..


 #includestdio.h
 #includeconio.h
 #define PRODUCT(x) (x*x)
 void main()
 {
 clrscr();
 int i=3,j;
 j=PRODUCT(i+1);
 printf(\n%d,j);
 getch();
 }

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

2011-07-10 Thread Manmeet Singh
Can think of a O(n^2) solution

On Sun, Jul 10, 2011 at 6:53 PM, raj singh ankurkaku...@gmail.com wrote:

 @yogesh- can u explain with an example pls?

  --
 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: Median of Binary Tree

2011-03-28 Thread Manmeet Singh
This is mean not the median

On Mon, Mar 28, 2011 at 8:42 PM, Raunak Agrawal raunak.ra...@gmail.comwrote:

 I am assuming that the median is the sum of all the values stored in the
 nodes divided by 2.

 So I am traversing all the nodes recursivelyand finding the median of
 them.


 On Mon, Mar 28, 2011 at 5:12 PM, kunal srivastav 
 kunal.shrivas...@gmail.com wrote:

 median is defined for a sorted list of numbers.. i cannot understand how
 you can traverse in O(n) in a normal binary tree.

 @raunak plz explain the solution


 On Mon, Mar 28, 2011 at 4:16 PM, bittu shashank7andr...@gmail.comwrote:

 @all try to understand the question as usual we have to do it in min.
 time  space complexity ..in mean Time O(n)  space o(1) At-most
 just tell em after doing in-order traversal where u will store the
 elements either in array or in set isn'tit  it will take O(n) extra
 space why not looks fro O(1) SPACE..IF M NOT CORRECT otherwise problem
 just become finding median in array which O(1) ..correct me if m
 wrong

 @Anurag wher u will store inorder of tree


 Thanks
 Shashank

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


-- 
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 ] 1march

2011-03-01 Thread Manmeet Singh
beetle

On Tue, Mar 1, 2011 at 1:38 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote:
 Riddle Problem Solution

 I am an insect. The beginning of my name is another insect's name. What am
 i?

 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] no. of passwords

2011-02-09 Thread Manmeet Singh
@ Dave : I think this shud also give the same result
C(26, 3) * C(26, 3) * C(10, 2) *  C(62, 2)

On Wed, Feb 9, 2011 at 7:16 PM, snehal jain learner@gmail.com wrote:

 how many passwords can be made if
 1. there should be atleast 3 capital letters
 2. atleast 3 small letters
 3. atleast 2 numbers 0-9
 4 the password should has length=10

 --
 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] no. of passwords

2011-02-09 Thread Manmeet Singh
Also it shud now be multiplied with Factorial of 10

On Thu, Feb 10, 2011 at 1:14 AM, Manmeet Singh mans.aus...@gmail.comwrote:

 @ Dave : I think this shud also give the same result
 C(26, 3) * C(26, 3) * C(10, 2) *  C(62, 2)

 On Wed, Feb 9, 2011 at 7:16 PM, snehal jain learner@gmail.com wrote:

 how many passwords can be made if
 1. there should be atleast 3 capital letters
 2. atleast 3 small letters
 3. atleast 2 numbers 0-9
 4 the password should has length=10

 --
 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: array(amazon microsoft)

2011-02-08 Thread Manmeet Singh
U using extra space, if you using extra space, simple C++ implementation
will be use a priority queue and do BFS.

On Wed, Feb 9, 2011 at 10:47 AM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote:

 @algoseeker

 mine approach is also the same but m inserting the elements in a min heap
 and you in a set.. i guess extraction of minimum element will be better in
 terms of complexity if we use a heap


 On Wed, Feb 9, 2011 at 10:01 AM, Ujjwal Raj ujjwal@gmail.com wrote:

 I see a scope of optimization in the algo.
 In step 2. Before inserting the element a[i][j], you can make sure that
 a[i][j-1] and a[i-1][j] are in the set. If not then do no insert a[i][j] in
 the heap. (considering the boundary condition, if j-1  0 or i-1  0 then
 assume it is true)

 Correct me if I am wrong.


 On Tue, Feb 8, 2011 at 11:40 PM, algoseeker newton.anu...@gmail.comwrote:

 Just coded the solution, it worked on all the test cases described here
 in this thread using the algo i described above :)

 The code is available at
 https://github.com/algoseeker/Interview/tree/master/sorting

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




 --
 With Regards,
 *Jalaj Jaiswal* (+919019947895)
 Software developer, Cisco Systems
 Final Year Undergraduate,
 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.



[algogeeks] Design question

2011-02-07 Thread Manmeet Singh
How to design a chess board using OOPS ? ?

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

2011-02-06 Thread Manmeet Singh
test case : a = -1, b = - 1
Result : fight successfully challenged dave's problem. Method returned 1
while it shud have returned -1.

On Sun, Feb 6, 2011 at 4:12 PM, Balaji S balaji.ceg...@gmail.com wrote:

 thanks..


 --
 balaji ;-)

  --
 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] what will be the output

2011-02-05 Thread Manmeet Singh
8, 32, 96

On Sat, Feb 5, 2011 at 2:46 PM, priya mehta priya.mehta...@gmail.comwrote:

 #include stdio.h
   #define PrintInt(expr) printf(%s : %d\n,#expr,(expr))

   *int* FiveTimes(*int* a)
   {
   *int* t;

   t *=* a**2 *+* a;

   *return* t;
   }

   *int* main()
   {
   *int* a *=* 1, b *=* 2,c *=* 3;

   PrintInt(FiveTimes(a));
   PrintInt(FiveTimes(b));

   PrintInt(FiveTimes(c));
   *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.comalgogeeks%2bunsubscr...@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] what will be the output

2011-02-05 Thread Manmeet Singh
because u not thinking of operator precedence :P :P

On Sat, Feb 5, 2011 at 2:52 PM, priya mehta priya.mehta...@gmail.comwrote:

 why is this happening?



 On Sat, Feb 5, 2011 at 2:51 PM, Manmeet Singh mans.aus...@gmail.comwrote:

 8, 32, 96

 On Sat, Feb 5, 2011 at 2:46 PM, priya mehta priya.mehta...@gmail.comwrote:

 #include stdio.h
   #define PrintInt(expr) printf(%s : %d\n,#expr,(expr))



   *int* FiveTimes(*int* a)
   {
   *int* t;



   t *=* a**2 *+* a;



   *return* t;
   }

   *int* main()
   {
   *int* a *=* 1, b *=* 2,c *=* 3;



   PrintInt(FiveTimes(a));
   PrintInt(FiveTimes(b));



   PrintInt(FiveTimes(c));
   *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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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] dp

2011-02-04 Thread Manmeet Singh
@ Shubham : Well Said :) :)

On Fri, Feb 4, 2011 at 8:01 PM, shubham singh
shubhamsisodia0...@gmail.comwrote:

 if (u r calling dp of spoj as basic)
 {
 i would say u are a champ already ;
 }
 else
 {
 do practise more on spoj

 }

 --
 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.comalgogeeks%2bunsubscr...@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] BISHOPS

2011-02-04 Thread Manmeet Singh
C/C++ user : Take input in a char array or string(if using C++) : a
now do string addition. : a = a + a;
now do string substraction. : a = a - 2.

Java user : Use BigInt class

On Fri, Feb 4, 2011 at 8:12 PM, Logic King crazy.logic.k...@gmail.comwrote:

 please help me solve the problem on SPOJ

 https://www.spoj.pl/problems/BISHOPS/


 The logic of the problem is very easy i.e. 2*n-2
 but i am getting WA bcoz i am not able to deal with the large inputs.[?]
 plz help me how to get this AC.


 #includestdio.h
 int main()
 {
 long long int n,bmax;
 while(scanf(%lld,n)!=EOF)
 {
 if(n==1)
 printf(%d\n,1);
 else
 {
 bmax=(2*n)-2;
 printf(%lld\n,bmax);

 }
 }
 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.comalgogeeks%2bunsubscr...@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.

325.png

Re: [algogeeks] Re: Good Maths Question

2011-01-24 Thread Manmeet Singh
What is incorrect in the given question, except the constraints not given.

On Mon, Jan 24, 2011 at 4:03 PM, juver++ avpostni...@gmail.com wrote:

 DP and clarify your incorrect question.

 --
 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.comalgogeeks%2bunsubscr...@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: Good Maths Question

2011-01-24 Thread Manmeet Singh
Also has any one solved https://www.spoj.pl/problems/MONONUM/
with only DP. I  would like to know the solution, as my solution works for
small nos. and then the ratio reduces to a simple mathematical formula.

On Mon, Jan 24, 2011 at 4:09 PM, Manmeet Singh mans.aus...@gmail.comwrote:

 What is incorrect in the given question, except the constraints not given.


 On Mon, Jan 24, 2011 at 4:03 PM, juver++ avpostni...@gmail.com wrote:

 DP and clarify your incorrect question.

 --
 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.comalgogeeks%2bunsubscr...@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: Good Maths Question

2011-01-24 Thread Manmeet Singh
ok, i thought he wanted the both, but he means ratio i guess. So, its the
same problem.

On Mon, Jan 24, 2011 at 4:21 PM, juver++ avpostni...@gmail.com wrote:

 @fight incorrect -
 how to calculate the number of the decreasing *n*-digit integers to the
 increasing *n*-digit integers

 --
 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.comalgogeeks%2bunsubscr...@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: Good Maths Question

2011-01-24 Thread Manmeet Singh
@JUVER++ : One personal question. Is this algo groups paying you something
or you among the admins :) :). As in every problem I find your name and with
a superb solution.

On Mon, Jan 24, 2011 at 4:26 PM, Manmeet Singh mans.aus...@gmail.comwrote:

 ok, i thought he wanted the both, but he means ratio i guess. So, its the
 same problem.


 On Mon, Jan 24, 2011 at 4:21 PM, juver++ avpostni...@gmail.com wrote:

 @fight incorrect -
 how to calculate the number of the decreasing *n*-digit integers to the
 increasing *n*-digit integers

 --
 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.comalgogeeks%2bunsubscr...@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: Good Maths Question

2011-01-24 Thread Manmeet Singh
n / 9.0 + 1 for n  20 works, before that I apply a simple DP. even i want
to know a gud DP based solution for the problem, with no formula used, as I
have done.
On Mon, Jan 24, 2011 at 11:43 PM, Logic King crazy.logic.k...@gmail.comwrote:

 hey, but what's the solution to the problem...how to calculate the
 ratio ??


 On Mon, Jan 24, 2011 at 11:19 PM, juver++ avpostni...@gmail.com wrote:

 @fight :) it's only for my pleasure :)

 --
 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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] power of 3

2011-01-21 Thread Manmeet Singh
Number exponentiation
On Fri, Jan 21, 2011 at 1:05 PM, snehal jain learner@gmail.com wrote:

 Given M, find if M = 3^x for some positive integer x efficiently. DO
 NOT think of log, pow 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.comalgogeeks%2bunsubscr...@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] power of 3

2011-01-21 Thread Manmeet Singh
this will be O(log(n) * log(n)) solution

On Fri, Jan 21, 2011 at 4:29 PM, abhijith reddy abhijith200...@gmail.comwrote:

 Below is code for modular exponentation in general

 // (a^b)%c
 int modexp(int a,int b,int c)
 {
int ans=1;
while(b)
{
  if(b1) ans=(ans*a)%c;
  a=(a*a)%c;
  b=1;
}
return ans;

 }


 On Fri, Jan 21, 2011 at 3:27 PM, juver++ avpostni...@gmail.com wrote:

 int l = 0, r = ...;
 while (l  r) {
   int m = (l + r) / 2;
   int p = power(3, m);
   if (p  M) r = m - 1;
   else if (p  M) l = m + 1;
   else print 3^m = M;
 }

 --
 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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] power of 3

2011-01-21 Thread Manmeet Singh
@snehal  : YUP

On Fri, Jan 21, 2011 at 5:57 PM, abhijith reddy abhijith200...@gmail.comwrote:

 @snehal .. misread it .. my apologies.


 On Fri, Jan 21, 2011 at 5:56 PM, abhijith reddy 
 abhijith200...@gmail.comwrote:

 O(lg(n)*lg(n)) is the complexity of the solution ! Not the solution.
 M=3^x
 We binary search on x and then compute 3^x in log(x) time using
 exponentiation. Hence the complexity.



 On Fri, Jan 21, 2011 at 5:50 PM, snehal jain learner@gmail.comwrote:

 @juvir++
 it was mentioned in question not to use log or power. isnt there any
 approach using bitwise operators


 On Fri, Jan 21, 2011 at 5:24 PM, Manmeet Singh mans.aus...@gmail.comwrote:

 this will be O(log(n) * log(n)) solution


 On Fri, Jan 21, 2011 at 4:29 PM, abhijith reddy 
 abhijith200...@gmail.com wrote:

 Below is code for modular exponentation in general

 // (a^b)%c
 int modexp(int a,int b,int c)
 {
int ans=1;
while(b)
{
  if(b1) ans=(ans*a)%c;
  a=(a*a)%c;
  b=1;
}
return ans;

 }


 On Fri, Jan 21, 2011 at 3:27 PM, juver++ avpostni...@gmail.comwrote:

 int l = 0, r = ...;
 while (l  r) {
   int m = (l + r) / 2;
   int p = power(3, m);
   if (p  M) r = m - 1;
   else if (p  M) l = m + 1;
   else print 3^m = M;
 }

 --
 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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] power of 3

2011-01-21 Thread Manmeet Singh
@juver++ : the above is a user defined function. but its possible to the
problem using bit wise operators.

On Fri, Jan 21, 2011 at 7:29 PM, juver++ avpostni...@gmail.com wrote:

 @above it's a user-defined function using fast exponentiation

 --
 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.comalgogeeks%2bunsubscr...@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] power of 3

2011-01-21 Thread Manmeet Singh
write n, n-1 to base 3
check if thr  gives 0, if it gives no. is of form 3^n

On Fri, Jan 21, 2011 at 8:04 PM, snehal jain learner@gmail.com wrote:

 @manmeet
 how?


 On Fri, Jan 21, 2011 at 7:36 PM, Manmeet Singh mans.aus...@gmail.comwrote:

 @juver++ : the above is a user defined function. but its possible to the
 problem using bit wise operators.


 On Fri, Jan 21, 2011 at 7:29 PM, juver++ avpostni...@gmail.com wrote:

 @above it's a user-defined function using fast exponentiation

 --
 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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] power of 3

2011-01-21 Thread Manmeet Singh
@ juver++ :  fight is my tc handle. here u can call me manmeet :) :)

On Fri, Jan 21, 2011 at 9:35 PM, juver++ avpostni...@gmail.com wrote:

 @fight good solution.
 3^n contains only one 1 in the 3-base representation.
 So write number M in base-3, and check if it contains only one digit(1).
 There is no need to find  with M-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.comalgogeeks%2bunsubscr...@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] Adobe Question

2011-01-21 Thread Manmeet Singh
how merge sort ?/

On Thu, Jan 20, 2011 at 11:23 PM, nishaanth nishaant...@gmail.com wrote:

 Ya as Ashish said hashing is the best solution :)


 On Fri, Jan 14, 2011 at 6:00 PM, Ashish Goel ashg...@gmail.com wrote:

 ideally, a hashMap would be preferred

 walk through one array and set the corresponding entry, and then through
 another array, if any entry found, then they are not disjoint.

 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652


 On Fri, Jan 14, 2011 at 3:35 PM, bittu shashank7andr...@gmail.comwrote:

 how to find if two arrays of size n are disjoint or not in O(n)
 time ?? You can use only O(n) space
 The elements are +ve in the range 0 to n power 100..



 Regards
 Shashank Mani

 --
 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 S.Nishaanth,
 Computer Science and engineering,
 IIT Madras.

 --
 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.comalgogeeks%2bunsubscr...@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] Distance in a dictionary

2011-01-21 Thread Manmeet Singh
whts complexity for this movegen()

On Fri, Jan 21, 2011 at 9:52 PM, nishaanth nishaant...@gmail.com wrote:

 Ok lets define the following functions.

 movegen()- gives the list of next move given the state. This is basically
 all the 1 distance words given the current word.

 heuristic()- this gives the number of non-matching characters of the given
 word with the goal word.

 Start from start state and expand.
 Now always choose the move which gives a lesser heuristic valued state.
 Stop if you reach the goal.

 You can refer to Russel Norvig book on AI for detailed explanation.



 Regards,

 S.Nishaanth,
 Computer Science and engineering,
 IIT Madras.

 --
 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.comalgogeeks%2bunsubscr...@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] Microsoft - DP problem

2011-01-20 Thread Manmeet Singh
It can be done in O(n) space too using DP :) :).
U dont need that flag, but that solution u said is absolutely correct.
On Thu, Jan 20, 2011 at 7:27 PM, Decipher ankurseth...@gmail.com wrote:

 There is a row of houses in which each house contains some amount of money.
 Write an algorithm that loots the maximum amount of money from these houses.
 The only restriction is that you cannot loot two houses that are directly
 next to each other.

  --
 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.comalgogeeks%2bunsubscr...@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: Microsoft - DP problem

2011-01-20 Thread Manmeet Singh
I dnt get the iterative version. Can u explain it. I can do it top down in
O(n) with state index
 I am at.
On Thu, Jan 20, 2011 at 11:30 PM, Avi Dullu avi.du...@gmail.com wrote:

 @^ Just check ur solution for boundary case ( n = 2) .. M$ is *generally*
 very strict about such mistakes :)


 Programmers should realize their critical importance and responsibility in
 a world gone digital. They are in many ways similar to the priests and monks
 of Europe's Dark Ages; they are the only ones with the training and insight
 to read and interpret the scripture of this age.



 On Thu, Jan 20, 2011 at 11:05 PM, Davin dkthar...@googlemail.com wrote:

 static int MaxLoot(int[] A, int n)
{
int[] S = new int[n];
S[0] = A[0];
S[1] = A[1];
S[2] = S[0] + A[2];


int maxloot = Math.Max(S[1], S[2]);



for (int i = 3; i  n; i++)
{
S[i] = Math.Max(S[i - 2], S[i - 3]) + A[i];
maxloot = Math.Max(maxloot, S[i]);
}



return maxloot;
 }

 On Jan 20, 7:30 pm, Manmeet Singh mans.aus...@gmail.com wrote:
  It can be done in O(n) space too using DP :) :).
  U dont need that flag, but that solution u said is absolutely correct.
 
 
 
 
 
 
 
  On Thu, Jan 20, 2011 at 7:27 PM, Decipher ankurseth...@gmail.com
 wrote:
   There is a row of houses in which each house contains some amount of
 money.
   Write an algorithm that loots the maximum amount of money from these
 houses.
   The only restriction is that you cannot loot two houses that are
 directly
   next to each other.
 
--
   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.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2Bunsubscribe@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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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] Dynamic Programming

2011-01-05 Thread Manmeet Singh
1-D simple dp with state current index you are at

On Wed, Jan 5, 2011 at 7:41 AM, Akash Agrawal akash.agrawa...@gmail.comwrote:

 didn't get the question correct...
 Can u cite an example...

 Regards,
 Akash Agrawal
 http://tech-queries.blogspot.com/



 On Wed, Jan 5, 2011 at 12:36 AM, Decipher ankurseth...@gmail.com wrote:

 Yuckdonald's is considering opening a series of restaurants along
 Quaint Valley Highway (QVH).The n possible locations are along a
 straight line, and the distances of these locations from the start of
 QVH are, in miles and in increasing order,m1;m2; : : : ;mn. The
 constraints are as follows:
  1)At each location,Yuckdonald's may open at most one restaurant.The
 expected profi t from opening a restaurant at location i is pi, where
 pi  0 and i = 1; 2; : : : ; n.
 2)Any two restaurants should be at least k miles apart, where k is a
 positive integer.
 Give an effi cient algorithm to compute the maximum expected total
 pro fit subject to the given
 constraints.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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] Dynamic Programming

2011-01-05 Thread Manmeet Singh
Can you elaborate how to put segment tree into picture

On Wed, Jan 5, 2011 at 2:57 PM, juver++ avpostni...@gmail.com wrote:

 Right. It can be solved simply in O(n^2). To optimize use segment trees.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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: Dynamic Programming

2011-01-05 Thread Manmeet Singh
int solve(int id) {
 if(id==n)
   return 0;
 int d = dp[id];
 if(~d) return d;
 d = 0;
 for(int i=id+1;in;i++) {
if(dis[i]-dis[id]=k) {
d ?= val[id] + solve(i);
}
}
return d;

}

Its O(n^2), and Juver++, is very correct.

On Wed, Jan 5, 2011 at 10:22 PM, Decipher ankurseth...@gmail.com wrote:

 I think your solution will take O(n3) time , as it will require three
 loops . 1st for index i , 2nd for first max and 3rd for second max .
 Instead we should take :
 dp[i] = max(dp[j]) + p[i] , where ji and m[i] - m[j]  k . Pls
 correct me if something is wrong .

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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: Dynamic Programming

2011-01-05 Thread Manmeet Singh
I am telling the DP O(n^2) solution, whts wrong in it??

On Wed, Jan 5, 2011 at 10:36 PM, juver++ avpostni...@gmail.com wrote:

 Unfortunately, you are wrong.
 We need one loop for i and that is all. All other things for searching max
 p[j] is solved by segment tree in O(log n).

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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: Dynamic Programming

2011-01-05 Thread Manmeet Singh
ok :):)

On Wed, Jan 5, 2011 at 10:43 PM, juver++ avpostni...@gmail.com wrote:

 I was replying to the @Decipher post. Not yours. :)
 Your algorithm seems to be ok.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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: Dynamic Programming

2011-01-05 Thread Manmeet Singh
In main just pass
answerIs = max(val[0], solve(0));


On Wed, Jan 5, 2011 at 10:49 PM, juver++ avpostni...@gmail.com wrote:

 Sorry, disregard my first proposition about index i.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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: add two numbers using bitwise operators

2010-12-31 Thread Manmeet Singh
Go through gates in Electronics, code will be easy to visualize.

On Fri, Dec 31, 2010 at 6:33 PM, juver++ avpostni...@gmail.com wrote:

 Yeah, add bits one by one from right to left, as for ordinary addition of
 two numbers in 10-th radix

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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: TopCoder Bad Neighbour

2010-12-22 Thread Manmeet Singh
class BadNeighbors {
public:
int maxDonations(vector int);
};
int dp[51][2][2];
int l;
vectorint v;
int solve(int id, int taken, int first) {
if(id==l)
return 0;
int d = dp[id][taken][first];
if(~d) return d;
d = 0;
if(id!=l-1) {
if(taken==0) {
d ?= v[id] + solve(id+1, 1, (id==0) | first);
d ?= solve(id+1, 0, first);
}
else {
d ?= solve(id+1, 0, first);
}
}
else {
if(first==1) {
d ?= solve(id+1, 1, first);
}
else {
if(taken==0) {
d ?= v[id] + solve(id+1, 1, first);
d ?= solve(id+1, 0, first);
}
else {
d ?= solve(id+1, 0, first);
}
}
}
return d;
}
int BadNeighbors::maxDonations(vector int v) {
:: v = v;
l = v.size();
memset(dp, -1, sizeof dp);
return solve(0, 0, 0);
}


On Wed, Dec 22, 2010 at 9:00 PM, mohit ranjan shoonya.mo...@gmail.comwrote:

 Ok, I got the recurrence relation at

 http://www.topcoder.com/tc?module=Staticd1=match_editorialsd2=tccc04_online_rd_4


 Mohit



 On Wed, Dec 22, 2010 at 8:33 PM, mohit ranjan shoonya.mo...@gmail.comwrote:

 Hi All,

 Can anybody help me with some hint for
 http://www.topcoder.com/stat?c=problem_statementpm=2402rd=5009


 Mohit


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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 output... ???

2010-12-14 Thread Manmeet Singh
When you pass an array as argument, it gets broken into a pointer. So you
get size as 4 for 32 bit machine.

On Tue, Dec 14, 2010 at 10:59 PM, Divesh Dixit 
dixit.coolfrog.div...@gmail.com wrote:

 #define SIZE 10
  void size(int arr[SIZE])
  {
  printf(size of array is:%d\n,sizeof(arr));
  }

  int main()
  {
  int arr[SIZE];
  size(arr);
  return 0;
  }

 the out put should be 40 considering 4 byte integer...

 but out put is only 4... how this is possible...
 and again if we modify it
 #define SIZE 10
 int main()
  {
  int arr[SIZE];
  printf(size of array is:%d\n,sizeof(arr));
  return 0;
  }
 we are getting the desired output as 40 byte...

 thankyou 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@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 algoge...@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.