[algogeeks] how to solve this?

2013-04-04 Thread arun kumar
Given an expression in the form of a string, solve for x. The highest power
of x in the expression will be equal to 1. Operators allowed are +, * and
-. These are all binary operators. So, 2x would be written as 2*x. Every
operator will be followed by a single term or a constant.

For example, consider the following equation:

2*x+5-(4*x-7+(4-2))=10*x-9 Given such an equation, we need to find a
solution to x

-- 
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, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] how to solve

2012-04-10 Thread Anurag Gupta
you dont need that much to do this problem

modify merge method in mergesort to calculate the sum in nlgn
think about it it's quite easy

you must have heard of Count Inversion problem , this is similar to that
problem

On Tue, Apr 10, 2012 at 6:49 AM, bharath kannan bharathgo...@gmail.comwrote:

 I dont know if it can be solved in O(n). But O(nlogn) can be done using
 BIT. Refer topcoder tutorial for Binary indexed trees.


 On Mon, Apr 9, 2012 at 10:56 AM, tarun chabarwal admin20...@gmail.comwrote:

 how should i approach this problem
 https://www.spoj.pl/problems/DCEPC206/
 can it be solved in O(n)..?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




-- 
Regards
Anurag Gupta
III Year Computer Engineering
Delhi Technological University
(Formerly Delhi College of Engineering)

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] how to solve

2012-04-09 Thread tarun chabarwal
how should i approach this problem
https://www.spoj.pl/problems/DCEPC206/
can it be solved in O(n)..?

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] how to solve

2012-04-09 Thread bharath kannan
I dont know if it can be solved in O(n). But O(nlogn) can be done using
BIT. Refer topcoder tutorial for Binary indexed trees.

On Mon, Apr 9, 2012 at 10:56 AM, tarun chabarwal admin20...@gmail.comwrote:

 how should i approach this problem
 https://www.spoj.pl/problems/DCEPC206/
 can it be solved in O(n)..?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] How to solve this

2011-12-23 Thread Ankur Garg
Suggest an algo with which u can find a random node in an infinitely long
linked list

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm 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] How to Solve This

2011-10-12 Thread Amol Sharma
@anshu- your code works fine.but can you plz explain how you concluded
this codei mean what's the logic behind to check   myset.size()  psize
?? ...as you are assuming  that it will be increase string and check
until this condition satisfies ??
--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
http://gplus.to/amolsharma99
http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://youtube.com/amolsharma99





On Wed, Oct 12, 2011 at 10:29 AM, shady sinv...@gmail.com wrote:

 thanks a lot for replying to the post... but try posting algorithm rather
 than actual code...

 On Mon, Oct 10, 2011 at 2:17 PM, anshu mishra 
 anshumishra6...@gmail.comwrote:

 string all1Multiple(int x)
 {
 string s;
 setint mySet;
 mySet.push(0);
 int psize, r=1;
 do
 {
 psize = mySet.size();
 s += '1';
 r = r % x;
 mySet.push(r);
 r = r * 10 + 1;
 } while(mySet.size()  psize);

 if (r != 1) return not Possible;
 return s;

 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm 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] How to Solve This

2011-10-12 Thread anshu mishra
@amol
I was not sure that for every number that has 3 in its unit place has one
multiple which has all one. So I used that is if the remainder is coming
that already appeared stop there coz it will make stuck in a loop.
for ex. remainders are
1 3 19 23 37 1 3 19  that will repeat.

but it in this case u can remove the set. Code will look more simpler.

string all1Multiple(int x)
{
string s;
int r=1;
do
{
s += '1';
r = r % x;
r = r * 10 + 1;
} while(r != 1);
return s;
}

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm 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] How to Solve This

2011-10-11 Thread prasad jondhale
23 has 3 in its unit place but it is not multiple of 111 or 11 or .
will u pls elaborate on the problem statement?

On Mon, Oct 10, 2011 at 2:17 PM, anshu mishra anshumishra6...@gmail.comwrote:

 string all1Multiple(int x)
 {
 string s;
 setint mySet;
 mySet.push(0);
 int psize, r=1;
 do
 {
 psize = mySet.size();
 s += '1';
 r = r % x;
 mySet.push(r);
 r = r * 10 + 1;
 } while(mySet.size()  psize);

 if (r != 1) return not Possible;
 return s;

 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 

Thanks  Regards
Prasad Y.Jondhale
M.Tech(software engg.),
Delhi College Of Engineering,
Main Bawana road,Delhi-110042
Ph-09540208001

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm 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] How to Solve This

2011-10-11 Thread Deoki Nandan
@moderator now is it not voilation of ur group terms ...Another code has
been posted ... What u 'll say now..

On 12 October 2011 03:30, prasad jondhale jondhale.pra...@gmail.com wrote:

 23 has 3 in its unit place but it is not multiple of 111 or 11 or .
 will u pls elaborate on the problem statement?


 On Mon, Oct 10, 2011 at 2:17 PM, anshu mishra 
 anshumishra6...@gmail.comwrote:

 string all1Multiple(int x)
 {
 string s;
 setint mySet;
 mySet.push(0);
 int psize, r=1;
 do
 {
 psize = mySet.size();
 s += '1';
 r = r % x;
 mySet.push(r);
 r = r * 10 + 1;
 } while(mySet.size()  psize);

 if (r != 1) return not Possible;
 return s;

 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --

 Thanks  Regards
 Prasad Y.Jondhale
 M.Tech(software engg.),
 Delhi College Of Engineering,
 Main Bawana road,Delhi-110042
 Ph-09540208001

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm 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
Deoki Nandan Vishwakarma
for Computer Science Interview Material see my home page
https://sites.google.com/site/deokinandanmaterials/subject-materialshttps://sites.google.com/site/deokinandanmaterials/

*
*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm 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] How to Solve This

2011-10-11 Thread shady
thanks a lot for replying to the post... but try posting algorithm rather
than actual code...

On Mon, Oct 10, 2011 at 2:17 PM, anshu mishra anshumishra6...@gmail.comwrote:

 string all1Multiple(int x)
 {
 string s;
 setint mySet;
 mySet.push(0);
 int psize, r=1;
 do
 {
 psize = mySet.size();
 s += '1';
 r = r % x;
 mySet.push(r);
 r = r * 10 + 1;
 } while(mySet.size()  psize);

 if (r != 1) return not Possible;
 return s;

 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm 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] How to Solve This

2011-10-10 Thread VIHARRI
For every number that has 3 in its units place has one multiple which
has all one's i.e. 111 is
such multiple and 13 has a multiple 11. Write a program to find
such multiple for any
number that has 3 at its units place.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm 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] How to Solve This

2011-10-10 Thread anshu mishra
string all1Multiple(int x)
{
string s;
setint mySet;
mySet.push(0);
int psize, r=1;
do
{
psize = mySet.size();
s += '1';
r = r % x;
mySet.push(r);
r = r * 10 + 1;
} while(mySet.size()  psize);

if (r != 1) return not Possible;
return s;
}

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm 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] How to solve this algorithm graph problem in polynomial time?

2011-09-26 Thread drealecs
I have a software problem and I'm searching for a solution but tried
different algorithm approach and nothing came out.
I'm not very familiar with all the graph algorithms and I hope there
is already a way to solve this kind of problems in polynomial time.

I need the algorithm for different task but I illustrated simple like
this:

The are N cities and there is a wanderer.
The time it takes for him to go from a town to another town is known -
Txy (from town x to town y).
From any town he can go to another town so it is a complete graph.
In each town there is a an amount of money Mx the wanderer wants to
collect.
It isn't enough time to pass through all cities.
Having the total available time T and the starting point i, the
problem is to find the best route so that the money he collects will
be maximum.

Input numbers range:
N is between 400 and 600
Mx(M1, M2, ...) are between 50 and 500, x between 1 and N
Txy are between 1 and 200, x and y are between 1 and N, x!=y
T is between 1000 and 5000


The problems is shared here:
http://www.evernote.com/shard/s119/sh/79f47a65-c1e6-44da-bbc0-7d10e36c7f71/374eda2f355c9a18d41ea19a20866fbc

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm 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] how to solve this

2011-08-16 Thread Sanjay Rajpal
Sort the array first and then check for the given conditions.
Sorting the array takes O(nlog n) in the worst case.


Sanjay Kumar
B.Tech Final Year
Department of Computer Engineering
National Institute of Technology Kurukshetra
Kurukshetra - 136119
Haryana, India


On Tue, Aug 16, 2011 at 6:16 PM, Raghavan its...@gmail.com wrote:


 A zero-indexed array A consisting of N integers is given. A triplet (P, Q,
 R) is triangular if  and
 A[P] + A[Q]  A[R],
 A[Q] + A[R]  A[P],
 A[R] + A[P]  A[Q].

 For example, consider array A such that

 A[0] = 10A[1] = 2A[2] =  5
 A[3] =  1A[4] = 8A[5] = 20
 Triplet (0, 2, 4) is triangular.

  public int triangle(int[] A)

 that, given a zero-indexed array A consisting of N integers, returns 1 if
 there exists a triangular triplet for this array and returns 0 otherwise.

 Assume that:

 N is an integer within the range [0..100,000];
 each element of array A is an integer within the
 range[-2,147,483,648..2,147,483,647].
 For example, given array A such that

 A[0] = 10A[1] = 2A[2] =  5
 A[3] =  1A[4] = 8A[5] = 20
 the function should return 1, as explained above. Given arrayA such that

 A[0] = 10A[1] = 50A[2] =  5
 A[3] =  1
 the function should return 0.
 Expected worst-case time complexity:  O(n log n)
 Expected worst-case space complexity: O(1)


 --
 Thanks and Regards,
 Raghavan KL




 --
 Thanks and Regards,
 Raghavan KL

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm 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] how to solve this

2011-08-16 Thread Sanjay Rajpal
Sort in increasing order.


Sanjay Kumar
B.Tech Final Year
Department of Computer Engineering
National Institute of Technology Kurukshetra
Kurukshetra - 136119
Haryana, India


On Tue, Aug 16, 2011 at 7:48 PM, Sanjay Rajpal sanjay.raj...@live.inwrote:

  Sort the array first and then check for the given conditions.
 Sorting the array takes O(nlog n) in the worst case.


 Sanjay Kumar
 B.Tech Final Year
 Department of Computer Engineering
 National Institute of Technology Kurukshetra
 Kurukshetra - 136119
 Haryana, India


   On Tue, Aug 16, 2011 at 6:16 PM, Raghavan its...@gmail.com wrote:


 A zero-indexed array A consisting of N integers is given. A triplet (P, Q,
 R) is triangular if  and
 A[P] + A[Q]  A[R],
 A[Q] + A[R]  A[P],
 A[R] + A[P]  A[Q].

 For example, consider array A such that

 A[0] = 10A[1] = 2A[2] =  5
 A[3] =  1A[4] = 8A[5] = 20
 Triplet (0, 2, 4) is triangular.

  public int triangle(int[] A)

 that, given a zero-indexed array A consisting of N integers, returns 1 if
 there exists a triangular triplet for this array and returns 0 otherwise.

 Assume that:

 N is an integer within the range [0..100,000];
 each element of array A is an integer within the
 range[-2,147,483,648..2,147,483,647].
 For example, given array A such that

 A[0] = 10A[1] = 2A[2] =  5
 A[3] =  1A[4] = 8A[5] = 20
 the function should return 1, as explained above. Given arrayA such that

 A[0] = 10A[1] = 50A[2] =  5
 A[3] =  1
 the function should return 0.
 Expected worst-case time complexity:  O(n log n)
 Expected worst-case space complexity: O(1)


 --
 Thanks and Regards,
 Raghavan KL




 --
 Thanks and Regards,
 Raghavan KL

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm 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] How to solve this problem

2011-08-14 Thread Ankur Garg
This is one question from Coreman

3rd Edition -

8-3-4 --  Sort n integers in the range 0 to n^3 -1 in O(n) time


Any ideas how to do this in O(n)

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] How to solve this problem

2011-08-14 Thread *$*
if extra space is allowed .. can use counting sort

On Sun, Aug 14, 2011 at 8:38 PM, Ankur Garg ankurga...@gmail.com wrote:

 This is one question from Coreman

 3rd Edition -

 8-3-4 --  Sort n integers in the range 0 to n^3 -1 in O(n) time


 Any ideas how to do this in O(n)

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Thx,
--Gopi

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm 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] How to solve this problem efficiently?

2007-09-04 Thread Ray

He has lost many books, since many of his friends borrow his books and
never bother to return them. He does not want to lose any more books
and has decided to keep a record of all books that he lends to his
friends. To make the task of borrowing a book a little difficult, he
has given the following instructions to his friends: when they borrow
a book, they must record in a register its position from the left
among the books currently on the shelf.

Suppose there are 5 books in the library and they are arranged as
follows:

26 1 42 15 3
If someone walks in and borrows the book 42, then he will record 3 in
the register because this book is the third from the left on the
shelf. Now the shelf looks like this:

26 1 15 3
If the next person borrow the book 3, he writes down 4 in the register
since this is currently the fourth book from the left on the shelf,
and so on.

Indraneel knows the initial arrangement of the books in his library at
the time that he introduced the register system. After a while he
examines his register and would like to know which books have been
borrowed. Your task is to write a program to help Indraneel solve this
problem.

Input format

The first line of the input contains a single integer M indicating the
number of books in Indraneel's library. The next line contains M
distinct positive integers describing the sequence in which the books
are arranged on the library shelf. The third line of input contains a
single integer N indicating the number of entries in the register.
This, in turn, is followed by N lines (lines 4 to N+3), each
containing one positive integer. The integer on line 3+i indicates the
position from left of the book ith book borrowed. (You may assume that
the number on line 3+i is at most M-i+1.)

Output format

N lines with one positive integer on each line. The number on line i
is the book borrowed by the ith borrower.

Test Data:

You may assume that 1 ≤ M ≤ 100 and 1 ≤ N ≤ 4000.

Example:

Here is the sample input and output corresponding to the example
discussed above.

Sample Input

5
26 1 42 15 3
2
3
4
Sample Output

42
3


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---