Re: [algogeeks] Distributed System problem

2015-01-14 Thread Piyush Grover
to algogeeks+unsubscr...@googlegroups.com. -- Piyush Grover *Be a traveler, not a tourist* -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr

Re: [algogeeks] optimization problem - N floors , N persons. minimum number of lift movements to move all persons in their respective floors

2013-05-31 Thread Piyush Grover
The problem is an array sorting problem. You are given an array of size N containing values 1 to N only. Sort it in O(N). Start from floor 1 till ith floor until you find a person on the wrong floor, take him to his respective floor take the guy from that floor and take him to his respective

[algogeeks] Clustering set problem

2013-04-19 Thread Piyush Grover
I have a practical problem, need an optimal solution for this *What is given?* Given *N* sets, each containing some jobs to be executed, such that no two sets are subsets of each other and number of jobs in *i-th* set is *ni N* . The jobs can have values between *1...k where k N*. Priority of

[algogeeks] Re: Clustering set problem

2013-04-19 Thread Piyush Grover
, Piyush Grover piyush4u.iit...@gmail.comwrote: I have a practical problem, need an optimal solution for this *What is given?* Given *N* sets, each containing some jobs to be executed, such that no two sets are subsets of each other and number of jobs in *i-th* set is *ni N*. The jobs can have

Re: [algogeeks] Re: Generating mazes

2013-01-29 Thread Piyush Grover
@Don can you give the logic of your rnd() function? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To unsubscribe from this group and stop receiving emails from it, send an email to algogeeks+unsubscr...@googlegroups.com. For more options,

Re: [algogeeks] Re: can we check a number has last digit 5 or not using bitwise operator.

2012-10-13 Thread Piyush Grover
The number which has 5 as last digit can be written as n = 4*a + b where b = 1 or 3 so if 4*a + 1 == n or 4*a + 3 == n; then n has 5 as a last digit. So code looks like: void main() { int n, m; scanf(%d, n); m = 2; m = 2; if(add(m, 1) == n || add(m,3) == n) puts(yes); else puts(no); }

Re: [algogeeks] Re: can we check a number has last digit 5 or not using bitwise operator.

2012-10-13 Thread Piyush Grover
forgot to assign: m = n; On Sun, Oct 14, 2012 at 2:27 AM, Piyush Grover piyush4u.iit...@gmail.comwrote: The number which has 5 as last digit can be written as n = 4*a + b where b = 1 or 3 so if 4*a + 1 == n or 4*a + 3 == n; then n has 5 as a last digit. So code looks like: void main

Re: [algogeeks] Re: Microsoft interview question

2012-05-21 Thread Piyush Grover
@Partha try with: A = {2, 2, 9} B= {1, 6, 6} On Mon, May 21, 2012 at 7:08 PM, partha sarathi Mohanty partha.mohanty2...@gmail.com wrote: a[] = [-1,-3,4,0,7,0,36,2,-3] b[] = [0,0,6,2,-1,9,28,1,6] b1[] = [0,7,0,36,4,-6,3,0,0] b2[] =[-1,-3,11,0,0,0,35,0,0] suma = 42 proda = -84*72*3

Re: [algogeeks] kth largest element in an unsorted list

2012-01-14 Thread Piyush Grover
you can do it in nlogk or n+klogn time. create a min-heap tree of size k with first k nodes. Add k+1..n nodes in the tree. Everytime you insert a node in the tree check if it's greater than the root node. If yes remove root node and insert the new node (logk operations). So time complexity will

[algogeeks] Facebook interview question.

2012-01-08 Thread Piyush Grover
Given a set S, find all the maximal subsets whose sum = k. For example, if S = {1, 2, 3, 4, 5} and k = 7 Output is: {1, 2, 3} {1, 2, 4} {1, 5} {2, 5} {3, 4} Hint: - Output doesn't contain any set which is a subset of other. - If X = {1, 2, 3} is one of the solution then all the subsets of X {1}

Re: [algogeeks] Facebook interview question.

2012-01-08 Thread Piyush Grover
: @Piyush : you are re-posting same problem which you had posted on 5 dec 2011. check this link :- http://groups.google.com/group/algogeeks/browse_thread/thread/8a58ea05c96f811b/ee74f8a4d7b68561?lnk=gstq=Maximal+possible+subsets+Algorithm#ee74f8a4d7b68561 On Mon, Jan 9, 2012 at 3:27 AM, Piyush

Re: [algogeeks] A bst problem

2011-12-10 Thread Piyush Grover
insertNode(node *head, int value){ node *new; if(head == null){ new = (node*)malloc(sizeof(node)); new-data = value; new-left = new-right = new-inoredrsucc = null; head = new; }else{ node *root = head; node *l, *r;

Re: [algogeeks] A bst problem

2011-12-10 Thread Piyush Grover
. Please check it. Regards, Aman. On Sat, Dec 10, 2011 at 6:30 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: insertNode(node *head, int value){ node *new; if(head == null){ new = (node*)malloc(sizeof(node)); new-data = value; new-left = new-right

Re: [algogeeks] A bst problem

2011-12-10 Thread Piyush Grover
not taken that into consideration. Please correct me if I am wrong. Regards, Aman, On Sat, Dec 10, 2011 at 7:37 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: I don't think so. First you added 15. 15-left = null=15-right=15-succ; add 13. (13 15) so 13-left = 13-right = null; 13-succ

Re: [algogeeks] A bst problem

2011-12-10 Thread Piyush Grover
-Piyush On Sat, Dec 10, 2011 at 8:28 PM, AMAN AGARWAL mnnit.a...@gmail.com wrote: Hi. So can you please tell me the modifications required so it works correctly. Regards, Aman. On Sat, Dec 10, 2011 at 8:22 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: yup, you are right.. On Sat, Dec

Re: [algogeeks] Maximal possible subsets Algorithm

2011-12-05 Thread Piyush Grover
: The possibility is ruled out by your question itself.There are exponential subsets of a set,so finding all subset is not possible in polynomail time. A backtracking approach is what you should think on, On Mon, Dec 5, 2011 at 12:51 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: Given a set S

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2011-12-05 Thread Piyush Grover
subsets where the addition of the weights results in maximum (each weight being considered only once)... Say for ex- The max weight is X=Wmax , then find all subsets which add up to X.. On Dec 5, 1:51 pm, Piyush Grover piyush4u.iit...@gmail.com wrote: Yeah but there's one more condition

Re: [algogeeks] Re: Maximal possible subsets Algorithm

2011-12-05 Thread Piyush Grover
As I mentioned earlier solution with exponential time-complexity is the obvious one. Is there any way to solve this problem by greedy/Dynamic algo? On Mon, Dec 5, 2011 at 5:24 PM, WgpShashank shashank7andr...@gmail.comwrote: @piyuesh , Saurabh isn't 3-Sum Suffics Here ? Another thought

[algogeeks] Maximal possible subsets Algorithm

2011-12-04 Thread Piyush Grover
Given a set S of objects having weights Wi and values Vi, and given a maximum weight Wmax. Find *ALL* the maximal subsets of set S such that Sum(Wi) = Wmax. Maximal subset means if {a, b, c} is a solution (such that Wa+Wb+Wc = Wmax) it means there doesn't exist any other object x in S such that

Re: [algogeeks] Google Question--Suggest Algo

2011-11-27 Thread Piyush Grover
Optimal split: [0,0][1,1][0,0][1,1][0,1][1,0] Expected value of optimal split: 0 + 1 + 0 + 1 + 1/2 + 1/2 = 3 why this is not the optimal split??? On Sun, Nov 27, 2011 at 6:58 PM, Ankur Garg ankurga...@gmail.com wrote: You have an array with *n* elements. The elements are either 0 or 1. You

Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-22 Thread Piyush Grover
, Nov 22, 2011 at 1:59 PM, anshu mishra anshumishra6...@gmail.comwrote: first try to understand the sol then comment. it is for binary tree not for BST. On Mon, Nov 21, 2011 at 10:25 PM, Piyush Grover piyush4u.iit...@gmail.com wrote: For BST it would be rather simpler. find the first node

Re: [algogeeks] LCA of a Binary tree not a binary search tree

2011-11-21 Thread Piyush Grover
For BST it would be rather simpler. find the first node which lies in between the two. On Wed, Nov 16, 2011 at 1:44 PM, anshu mishra anshumishra6...@gmail.comwrote: Node *LCA(node *root, node *e1, node *e2, int x) { Node *temp =NULL; Int y = 0;

Re: [algogeeks] Linked List Problem-Suggest Algo

2011-11-21 Thread Piyush Grover
As you mentioned, the numbers designating the gaps can only be repeated so in your example 2 20 can be broken into 19 1 but 19 is already there in the list (the first couplet) and it's not the one which describes the gap. can you please clarify? On Mon, Nov 21, 2011 at 5:23 AM, Ankur Garg

Re: [algogeeks] Amazon - array problem

2011-09-29 Thread Piyush Grover
Given array A. Compute array B such that B[0] = 1; for(i = 1; i n; i++) B[i] = B[i-1]*A[i-1] now, mul = 1; for (i = n-2; i =0; i--){ mul = mul*A[i]; B[i] = B[i]*mul; } On Fri, Sep 30, 2011 at 2:18 AM, Hatta tmd...@gmail.com wrote: are the algorithm instance always a sequence

Re: [algogeeks] Amazon - array problem

2011-09-29 Thread Piyush Grover
sorry, one mistake... mul = mul*A[i]; it should be mul = mul*A[i+1] On Fri, Sep 30, 2011 at 2:57 AM, Piyush Grover piyush4u.iit...@gmail.comwrote: Given array A. Compute array B such that B[0] = 1; for(i = 1; i n; i++) B[i] = B[i-1]*A[i-1] now, mul = 1; for (i = n-2; i =0; i

Re: [algogeeks] Re: random function

2011-09-19 Thread Piyush Grover
as such there is no specific method to generate random number but if you have to implement it then you can generate a pseudo random generator using cur_time_value_in_mili_seconds mod n. On Mon, Sep 19, 2011 at 9:24 PM, Don dondod...@gmail.com wrote: The most common way that it works would be

Re: [algogeeks] Re: Microsoft Question

2011-09-18 Thread Piyush Grover
for(i = 0; i n; i++) for(j = 0; j n; j++){ setColor(i, j) = black; if(A[i][j] == str[0]){ setColor(i, j) = blue; a = findWord(A, i, j, str, 1) if(!a) setColor(i, j) = black; else break; } } findWord(A, i, j, str, k){ if(k

Re: [algogeeks] Re: Microsoft Question

2011-09-18 Thread Piyush Grover
sry, in the findWord function all a's are different e.g a0, a1a7 and if(!a) is actually if(a0||a1||...||a7) thnx piyush On Mon, Sep 19, 2011 at 1:10 AM, Piyush Grover piyush4u.iit...@gmail.comwrote: for(i = 0; i n; i++) for(j = 0; j n; j++){ setColor(i, j) = black

Re: [algogeeks] Array ques based on correlation factor

2011-09-17 Thread Piyush Grover
=Take a function rand() which returns value between [0, 1) uniformly or use function rand(n) = n*rand() which return value between 0- (n-1) using uniform probability distribution. =Now create a array A[0..n-1] = [0..n-1] now rake an array R. k = n; for(i = 0; i n; i++){ a = rand(k);

Re: [algogeeks] Re: Math Puzzle

2011-09-15 Thread Piyush Grover
Don is right if R = 0, P = 1 and Q = -1 then the given expression is UNDEFINED!!! On Thu, Sep 15, 2011 at 10:16 PM, abhinav gupta guptaabhinav...@gmail.comwrote: Shut up...its 3,, On Thu, Sep 15, 2011 at 9:43 AM, Don dondod...@gmail.com wrote: It might be 3, but it doesn't have to

Re: [algogeeks] Re: Math Puzzle

2011-09-15 Thread Piyush Grover
to 3. Don On Sep 15, 11:57 am, abhinav gupta guptaabhinav...@gmail.com wrote: u cnt divide a number by 0..that thing is self undrstod On Thu, Sep 15, 2011 at 9:49 AM, Piyush Grover piyush4u.iit...@gmail.comwrote: Don is right if R = 0, P = 1 and Q = -1 then the given

Re: [algogeeks] ms question

2011-09-12 Thread Piyush Grover
it should be: (1/n)^n * (1 + 2 + 2^2 + 2^3 +(n/2)+1 terms) = {2^(1 + n/2) - 1}*(1/n)^n when n even (1/n)^n * (1 + 2 + 2^2 + 2^3 +(n-1/2)+1 terms) = {2^(1 + (n-1)/2) - 1}*(1/n)^n when n is odd -Piyush On Mon, Sep 12, 2011 at 8:01 PM, sandeep nagamalli nsandee...@gmail.comwrote:

Re: [algogeeks] ms question

2011-09-12 Thread Piyush Grover
Sry i was little wrong: nC0*(1/n)^n + nC2 *2*(1/n)^n + nC4*2^2*(1/n)^n++nCn*2^(n/2)*(1/n)^n when n is even nC0*(1/n)^n + nC2 *2*(1/n)^n + nC4*2^2*(1/n)^n++nCn-1*2^(n-1/2)*(1/n)^n when n is odd On Mon, Sep 12, 2011 at 10:08 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: it should

Re: [algogeeks] Re: worst case complexity

2011-09-10 Thread Piyush Grover
O(n^4) Just think... for(i = 0; i n; i++) for(j = 0; j i; j++) has Time Complexity O(n^2) then how come for(i = 0; i n; i++) for(j=0; ji*i; j++) it's O(n^2).. it's...1 + 2^2 + 3^2 + ...n^2 which is O(n^3) but adding one for(k=0; k j; k++) will not make

Re: [algogeeks] What would be the ans.

2011-09-10 Thread Piyush Grover
I got.. 1.) 2/pi 2.) 3.) 0.5 - (1/pi) On Sat, Sep 10, 2011 at 2:47 PM, Ishan Aggarwal ishan.aggarwal.1...@gmail.com wrote: three points are randomly chosen on a circle.what the probability that 1.triangle formed is right angled triangle. 2.triangle formed is acute angled triangle.

Re: [algogeeks] What would be the ans.

2011-09-10 Thread Piyush Grover
Sorry guys.. I was wrong, radius also matters here... still investigating On Sat, Sep 10, 2011 at 3:56 PM, sarath prasath prasathsar...@gmail.comwrote: @Piyush Grover: please explain ur answer On Sat, Sep 10, 2011 at 3:30 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: I got

Re: [algogeeks] What would be the ans.

2011-09-10 Thread Piyush Grover
be 1/3 for each of the three options... On Sat, Sep 10, 2011 at 4:48 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: Sorry guys.. I was wrong, radius also matters here... still investigating On Sat, Sep 10, 2011 at 3:56 PM, sarath prasath prasathsar...@gmail.comwrote: @Piyush

Re: [algogeeks] What would be the ans.

2011-09-10 Thread Piyush Grover
it would be close to zero but not exactly zero. On Sat, Sep 10, 2011 at 6:28 PM, Ishan Aggarwal ishan.aggarwal.1...@gmail.com wrote: How u calculated this?? On Sat, Sep 10, 2011 at 6:19 PM, Neha Singh neha.ndelhi.1...@gmail.comwrote: The correct ans is : for right angled triangle : 0

Re: [algogeeks]

2011-09-09 Thread Piyush Grover
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

Re: [algogeeks] sorting

2011-09-08 Thread Piyush Grover
It depends on the use cases. If you have less elements of order of( say 100) then even insertion sort can be a better choice. It's in-place sorting algo and can perform sorting as it receives the elements like a stream. If you have large number of elements and all the elements can't be

Re: [algogeeks] Objective Question

2011-09-07 Thread Piyush Grover
Option a) i didn't understand properly, please elaborate!! Option b) certainly yes. Option c) No (remember, the size of the table is subjective) Option d) yes (use index on the column used in the where clause) On Wed, Sep 7, 2011 at 8:58 PM, Mani Bharathi manibharat...@gmail.comwrote: when

Re: [algogeeks] Re: Element in Array Repeated Even Number of Times

2011-09-07 Thread Piyush Grover
i don't think it's of O(n) for even it's actually easy. Take the xor of all the elements you will left with the element which appears odd number of times. O(n) but for the odd case, we need to use extra space. Use hash map to keep the count of each number and take the odd one out, i mean the even

Re: [algogeeks] answer these interesting questions

2011-09-07 Thread Piyush Grover
1.)a 2.)b 3.)b 4)b On Wed, Sep 7, 2011 at 11:08 PM, Mani Bharathi manibharat...@gmail.comwrote: “Kya-Kya” is an island inhabitants of which always answer any question with two answers , one of which is true and the other is false . 1.You are walking on a road and came to a park . You ask

Re: [algogeeks] answer these interesting questions

2011-09-07 Thread Piyush Grover
4) a and b On Thu, Sep 8, 2011 at 12:08 AM, Piyush Grover piyush4u.iit...@gmail.comwrote: 1.)a 2.)b 3.)b 4)b On Wed, Sep 7, 2011 at 11:08 PM, Mani Bharathi manibharat...@gmail.comwrote: “Kya-Kya” is an island inhabitants of which always answer any question with two answers , one

Re: [algogeeks] virtual memory

2011-09-06 Thread Piyush Grover
it's a subjective question. If you have 100GB of main memory and 2 GB of virtual memory and you are running very light weight programs then nothing will happen. The system memory has enough space to take care of all the applications but if your system is heavily loaded with processes then it

Re: [algogeeks] MS question

2011-09-05 Thread Piyush Grover
One thing i would like to know is 01/02/2011 needs to be considered or 1/02/2011. thnx On Mon, Sep 5, 2011 at 11:48 PM, Neha Singh neha.ndelhi.1...@gmail.comwrote: @yogesh: its stiil not correct. There r many test cases where ur solution will fail -- You received this message because you

Re: [algogeeks] character count in array

2011-09-03 Thread Piyush Grover
use hashing u'll get O(1) space.. @rahul...why not?? On Sat, Sep 3, 2011 at 7:13 PM, priya ramesh love.for.programm...@gmail.com wrote: use hashing -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: Find Max Sum Value Pairs

2011-09-03 Thread Piyush Grover
:09 pm, Piyush Grover piyush4u.iit...@gmail.com wrote: if I have understood the question correctly then: a[n-1] + b[i] a[j] + b[i] for all 0 = j n-1 and a[j] + b[n-1] a[j] + b[i] for all 0 = i n-1 therefore, i = j =n-1; count = 1; S[0] -- (a[n-1], b[n-1]) p = a[n-1] + b[n-2

Re: [algogeeks] Re: Find Max Sum Value Pairs

2011-09-02 Thread Piyush Grover
if I have understood the question correctly then: a[n-1] + b[i] a[j] + b[i] for all 0 = j n-1 and a[j] + b[n-1] a[j] + b[i] for all 0 = i n-1 therefore, i = j =n-1; count = 1; S[0] -- (a[n-1], b[n-1]) p = a[n-1] + b[n-2]; q = a[n-2] + b[n-1] while(count n){ if(p q){ j--;

Re: [algogeeks] Re: Find Max Sum Value Pairs

2011-09-02 Thread Piyush Grover
Since A(n) and B(n) are sorted so in the pair (a[i], b[j]) either i = n-1 or j = n-1 or both. 1.) so the first element is (a[n-1], b[n-1]) 2.) now, we have two numbers to compare p = a[n-1]+ b[n-2] and q = a[n-2]+b[n-1] 3.) if pq then p = a[n-1]+b[n-3] else q = a[n-3] + b[n-1] and repeat in

Re: [algogeeks] SEEK advice very urgent

2011-09-01 Thread Piyush Grover
@Raj From my personal experience I can just say, being an Indian you will get more respect in Japan rather in the US. The problem you may face is the language and the food. If you are non veg, well n good but if you are veg you will have to cook it by yourself, there are indian curry restaurants

Re: [algogeeks] SEEK advice very urgent

2011-09-01 Thread Piyush Grover
@Raj I did two months summer internship there in tokyo. I did internship in scotland also and what I can say comparing the two is I got royale treatment in Japan. People are more keen about indians and Indian culture but in UK no one bother for you and the same I heard from friends who worked in

Re: [algogeeks] loop in link list

2011-08-31 Thread Piyush Grover
This is fine but adding a twist to it. Find number of nodes which are not in the loop. On Wed, Aug 31, 2011 at 6:27 PM, rahul sharma rahul23111...@gmail.comwrote: int loop(void *head1,void *head2) { //head1 and head2 initialized to start; while(head1!=NULL head2!=NULL) { head1=head1-next;

Re: [algogeeks] graph

2011-08-31 Thread Piyush Grover
loop within a loop, what exactly that means?? Nee to consider the planarity or two loops sharing common edge/s?? On Wed, Aug 31, 2011 at 8:46 PM, MAC macatad...@gmail.com wrote: Q The question asked in interview of a startup : suppose you have a graph as shown bellow : please see the

Re: [algogeeks] Re: microsoft interview

2011-08-31 Thread Piyush Grover
What's wrong with this?? for( i = 0 ; i n ; ++i ) for( j = 0 ; j m ; ++j ) if( a[i][j] != 0 ) a[i][0] = a[0][j] = 1; for( i = 0 ; i n ; ++i ) for( j = 0 ; j m ; ++j ) if( a[i][0] + a[0][j] != 0 ) a[i][j] = 1; On Thu, Sep 1, 2011 at 5:45 AM, Dave

Re: [algogeeks] Re: Custom Random Generator

2011-08-30 Thread Piyush Grover
and no looping. int custRand(int n) { int a = rand(n*n+n); int b = a / n; a %= n; return (b a) ? n+a-b+1 : n-a+b; } On Aug 29, 10:48 am, Piyush Grover piyush4u.iit...@gmail.com wrote: Given a function rand(n) which returns a random value between 1...n assuming equal

Re: [algogeeks] affect of change

2011-08-30 Thread Piyush Grover
I think, it should be C D; a = i++ = a=i; i = i+1; a = ++i; = i = i+1; a = i; in similar fashion, D gets affected. @ Raj...how come?? On Tue, Aug 30, 2011 at 8:11 PM, raj kumar megamonste...@gmail.com wrote: code becomes more efficient -- You received this message because you are

Re: [algogeeks] Amazon written test ques

2011-08-30 Thread Piyush Grover
#include stdio.h #include string.h typedef struct node{ struct node *next; char *str; }node; node *M; void swap(char *a, char *b){ char t = *a; *a = *b; *b = t; } void add(char *str){ if(M == NULL){ M = (node *)malloc(sizeof(node)); M-str = (char

Re: [algogeeks] Re: Custom Random Generator

2011-08-29 Thread Piyush Grover
the result to be the orthogonal distance from the diagonal. That is what the formula computes. Don On Aug 29, 11:28 am, Piyush Grover piyush4u.iit...@gmail.com wrote: I understand what you are doing in the loop but return statement is not clear to me. Can you explain. On Mon, Aug 29, 2011

Re: [algogeeks] Re: Custom Random Generator

2011-08-29 Thread Piyush Grover
to be the orthogonal distance from the diagonal. That is what the formula computes. Don On Aug 29, 11:28 am, Piyush Grover piyush4u.iit...@gmail.com wrote: I understand what you are doing in the loop but return statement is not clear to me. Can you explain. On Mon, Aug 29, 2011

Re: [algogeeks] Re: Find all the subsets whose sum = k

2011-08-29 Thread Piyush Grover
http://mathoverflow.net/questions/57371/find-all-maximal-subsets-of-a-set-of-integers-whose-sum-does-not-exceed-a-number actual question is this. On Sat, Aug 27, 2011 at 9:56 AM, rahul sharma rahul23111...@gmail.comwrote: yeah i wen first post answer i said it is for finding sum=k; n just add

Re: [algogeeks] c program

2011-08-28 Thread Piyush Grover
it's a quine problem. char*f=char*f=%c%s%c; main(){ printf(f,34,f,34,10); }%c; main() { printf(f,34,f,34,10); } I have used whitespaces to make it understand. On Sun, Aug 28, 2011 at 11:39 AM, rahul sharma rahul23111...@gmail.comwrote: program whose output is the program itself???

Re: [algogeeks] Re: c program

2011-08-28 Thread Piyush Grover
on paper. You would be able to understand it. -Piyush On Sun, Aug 28, 2011 at 11:46 AM, rahul sharma rahul23111...@gmail.comwrote: plz expalin char*f= On Aug 28, 11:12 am, Piyush Grover piyush4u.iit...@gmail.com wrote: it's a quine problem. char*f=char*f=%c%s%c; main

Re: [algogeeks] Re: c program

2011-08-28 Thread Piyush Grover
one or two more statements then it will require corresponding change in char *f...can i open the same file with f open n prin t it out? On Aug 28, 11:31 am, Piyush Grover piyush4u.iit...@gmail.com wrote: char*f=char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c; f is a global pointer

Re: [algogeeks] Re: math puzzle

2011-08-28 Thread Piyush Grover
3x+4y = 60 it's a straight line equation whose x intercept is 20 and y intercept is 15. Draw it in first quadrant (as x, y are positive integers) now x = (60 - 4y)/3 = 4(15-y)/3 now for y = 1, 2...15 you need to check whether (15-y) is divisible by 3 or not. It's simple y = 3, 6, 9, 12 -Piyush

Re: [algogeeks] Re: amazon ques :Online round

2011-08-27 Thread Piyush Grover
I don't understand your point if y[i] y[i+1] how come the slope is positive? It's just that the i'th line will lie under line i+1th line. On Sat, Aug 27, 2011 at 5:11 PM, monish001 monish.gup...@gmail.com wrote: If I correctly understood the question, It says: 1. 0= x[i] =1 for all i and for

Re: [algogeeks] Re: amazon ques :Online round

2011-08-27 Thread Piyush Grover
, y0)) ) return(i, i+1) else return(i-1, i); } } On Sat, Aug 27, 2011 at 5:59 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: I don't understand your point if y[i] y[i+1] how come the slope is positive? It's just that the i'th line will lie under line i+1th line. On Sat, Aug 27

Re: [algogeeks] Re: amazon ques :Online round

2011-08-27 Thread Piyush Grover
pardon 1 small mistake instead of if(i == 0 || i == n) return (lower, upper); it should be if(i == lower || i == upper) return (lower, upper); On Sat, Aug 27, 2011 at 8:31 PM, Piyush Grover piyush4u.iit...@gmail.comwrote: satisfy the point on lines, for point(x,y) to lie in between

[algogeeks] Find all the subsets whose sum = k

2011-08-26 Thread Piyush Grover
Here is a problem: Given an array of size n. Find all the MAXIMAL subsets whose sum is = K. The solution is not a concern, the optimization is required. -piyush -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

Re: [algogeeks] Re: Find all the subsets whose sum = k

2011-08-26 Thread Piyush Grover
...@gmail.com wrote: This is the knapsack problem. Find a polynomial-time solution and you will be a hero. Don On Aug 26, 12:43 pm, Piyush Grover piyush4u.iit...@gmail.com wrote: Here is a problem: Given an array of size n. Find all the MAXIMAL subsets whose sum is = K

Re: [algogeeks] apti!

2011-08-26 Thread Piyush Grover
it's basic unitary method problem: x men do work in 10 days 1 man will do-in 10*x days x-10 men do it in 10*x/(x-10) = (10+10) Solve it and x = 20 it can't be 130 On Fri, Aug 26, 2011 at 11:53 PM, gmagog...@gmail.com gmagog...@gmail.comwrote: @Rahul Assume the productivity of each man

Re: [algogeeks] Re: puzzle

2011-08-26 Thread Piyush Grover
Cut the rope in 50mtrs and 100mtrs length. Make a small loop(of negligible length at one end of the 50 mtrs rope) Tie the other end of the rope at the top and from the loop end side pass the 100mtrs rope such that you have both the ends of 100mtrs rope in your end. now get down at 100mtrs peg