if N = 64 then we can convert all rows in an equivalent integer and then
sort all numbers and print distinct No.s
else
Worst case Solution would be to to check for each pair of rows and match -
O(N^3)
one more solution i can think of is to divide and conquer solution which
goes like this
based
u can use hashing ...
hash fun can b base2 to base10
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
In any case, I don't think the complexity can be improved from O(n^2)
because even in creating hash function every column element of every row
which itself is N^2 only..
On Tue, Jun 28, 2011 at 11:38 AM, Ankit Agrawal
ankitmnnit.agra...@gmail.com wrote:
u can use hashing ...
hash fun can b
@Ankit
if N is large how will you hash the rows, numbers will be very large
can you explain using given example ?
On Tue, Jun 28, 2011 at 11:38 AM, Ankit Agrawal
ankitmnnit.agra...@gmail.com wrote:
u can use hashing ...
hash fun can b base2 to base10
--
You received this message because
GOT AC IN .02 SEC .:)))
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
@VAIBHAV.ur logic fails in many
cases...like G
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this
Shortest simple path problem is in P, but Longest simple path problem
is in NP. Explain why the greedy choice(on edge weights) is not
suitable in the second case .
Ankit Sambyal
BITS Pilani
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To
@Sanket: Don't know, it works fine on my side...
--
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/-/6E5jS41APUMJ.
To post to this group, send email to
I have 1 more solution :-
#includestdio.h
#includestring.h
main()
{
int i,j,l;
char arr[100];
printf(Enter the string\n);
fgets(arr,100,stdin);
for(i=0,l=strlen(arr),j=l;i=l/2;i++)
{
arr[j--]=arr[i];
arr[i]=arr[j];
}
for(i--;il;i++)
arr[i]=arr[i+1];
arr[i]='\0';
@kartik well i hv written before trailing G's can be left in calculation
so it works fr GG.
On 6/28/11, kartik sachan kartik.sac...@gmail.com wrote:
@VAIBHAV.ur logic fails in many
cases...like G
--
You received this
@amit
Check out your IQ
On Tue, Jun 28, 2011 at 2:43 AM, amit kumar amitthecoo...@gmail.com wrote:
how 2??
On Tue, Jun 28, 2011 at 2:40 AM, gmagog...@gmail.com
gmagog...@gmail.comwrote:
if( links can be melt and made into smaller links )
{
return 1;
}
else
{
return 2;
Anand,
The code mentioned on your blog is wrong.
http://codepad.org/n7YLkqaR
On Mon, Jun 27, 2011 at 5:28 AM, Anand anandut2...@gmail.com wrote:
http://anandtechblog.blogspot.com/2010/09/given-array-of-numbers-replace-each.html
On Sun, Jun 26, 2011 at 10:12 AM, ross jagadish1...@gmail.com
There are 6 beer bottle nd one is **not** poisoned. we have mice who will
die
within 14 hrs after drinkin poisned beer. In 24 hrs we have to find
*nonpoisonous *beer bottle. How many no of mice we require to find out
non poisoned bottle.?
--
You received this message because you are subscribed
check the archives before asking a question. it has already been answered as
3.
On Tue, Jun 28, 2011 at 1:13 PM, oppilas . jatka.oppimi...@gmail.comwrote:
There are 6 beer bottle nd one is **not** poisoned. we have mice who will
die
within 14 hrs after drinkin poisned beer. In 24 hrs we have
#include stdio.h
#include stdlib.h
void revers(char *s)
{
if(*s)
{
revers(++s);
s--;
printf(%c ,*s);
}
}
int main(int argc, char *argv[])
{
char arr[]=string;
revers(arr);
system(PAUSE);
return 0;
}
@Dave:can u please explain the second method.
On Mon, Jun 27, 2011 at 11:24 PM, Dave dave_and_da...@juno.com wrote:
@Nishant: Here are a couple of O(n) alternatives, given that there are
a limited number of last characters and no requirement to break ties
in any particular way:
1. A
List[letter] - linked list of all words with the last character as letter.
Then iterate over all letters and concatenate lists.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To view this discussion on the web visit
no, you arent actually reversing anything, you are just printing.
On Tue, Jun 28, 2011 at 11:40 AM, Kamakshii Aggarwal
kamakshi...@gmail.comwrote:
#include stdio.h
#include stdlib.h
void revers(char *s)
{
if(*s)
{
revers(++s);
s--;
@Kartik
Please tell me what logic you're following.
@varun
This strategy failed. I tried submitting.
GBGBBGGBBBGGBBBGBGGBGGBGBGG
101001100011000101101101011
You can try the above case.
--
You received this message because you are subscribed to the Google Groups
Algorithm
I will explain with an example:
3
a --- b
| |
| |
| 5 | 4
| |
c-d
1
lets say we want to find the shortest path from c to b,
denote sp(x,y) as the length of the shortest path from x to y
SP(c,b) = min( SP(c,a) + SP(a,b) , SP(c,d) +
anonymous u have to play with the index no of either G or
B...and see how many shift it will require to reach it original
postion then max will be the ans..
well GBGBBB
if we start from right to left then G=3 and G=5
first G have reach to 0 pos and second G have to reach
Tell me the approach you have thought of.
On Jun 28, 8:39 am, Ashish Goel ashg...@gmail.com wrote:
Hi,
The implementation is simple using 2 stacks, however we also need to make
sure that if queue length is say x, we are able to enqueue x elements. As
per my understanding, i could think of
@kartik the sequence 101001100011000101101101011 can be done
in 25 iterations
whts urs?
On 6/28/11, kartik sachan kartik.sac...@gmail.com wrote:
anonymous u have to play with the index no of either G or
B...and see how many shift it will require to reach it original
postion
apologies :)
so the answer for this is 5 ?
On Tue, Jun 28, 2011 at 2:14 PM, sunny agrawal sunny816.i...@gmail.comwrote:
@shady
this is modified Question.here 5 beers are poisoned
On Tue, Jun 28, 2011 at 1:37 PM, shady sinv...@gmail.com wrote:
check the archives before asking a
1.Given an array of integers and another integer X - create an algorithm to
determine if the sum of any two integers in the array would result in x
2. design a ADT to implement push(), pop() method as stack, and also has a
getMinElement(). Require that getMinElement() is constant time but
@kartik it's wrng got it
On 6/28/11, vaibhav agarwal vibhu.bitspil...@gmail.com wrote:
@kartik the sequence 101001100011000101101101011 can be done
in 25 iterations
whts urs?
On 6/28/11, kartik sachan kartik.sac...@gmail.com wrote:
anonymous u have to play with the index no of
@ vaibhav i have submitted my concept in spoj and it got AC in .02 sec
i am saying for u have to play with index of EITHER of G or B
now u have to think logic by taking two or more exmaple and shift it
in...do it in paperu will see some pattern
--
You received this message
for second problem, you can create a stack of having each element as a node
having the current value as well as pointer to the next smallest value
present below it. This can solve all 3 operations in constant time.
Thanks,
Anurag
On Tue, Jun 28, 2011 at 3:00 PM, vikas mehta...@gmail.com wrote:
For 1st question :
First sort the array. O(n*logn)
then we can easily find 2 elements in the array which sum to X.
---O(n)
So, Time complexity of the algo : O(n*logn)
Question 2 is trivial..
On Tue, Jun 28, 2011 at 2:30 AM, vikas mehta...@gmail.com wrote:
Check out my solution above :)
Its reversing the string
On Tue, Jun 28, 2011 at 1:56 PM, shady sinv...@gmail.com wrote:
no, you arent actually reversing anything, you are just printing.
On Tue, Jun 28, 2011 at 11:40 AM, Kamakshii Aggarwal
kamakshi...@gmail.com wrote:
#include stdio.h
what will be the oldDiff initially. can u plz explain with a egsample
--
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/-/NXQqyUTbdlkJ.
To post to this group,
So, if the space doesnt matter. We can have an array A for hashing. So
first we will find the minimum element in array suppose M. and in the
other traversal of array, we will calculate for each element Ai in
array Ai + (-M). So if it exceeds N then elements are not consecutive
and other check that
answer is 3
--
Thanks and Regards,
Manish Pathak **
TimesJobs.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
Manish can you explain how?
Please read the question carefully and explain accordingly.
On Tue, Jun 28, 2011 at 3:40 PM, Manish Pathak pathak@gmail.com wrote:
answer is 3
--
Thanks and Regards,
Manish Pathak **
TimesJobs.com
--
You received this message because you are
I think the answer is 5.
To know which one is poisonous, you have to use one mouse.
How to use 3 mice achieve this goal?
If all the 3 mice drink the poisonous beer, they will die first, how
does the test go on?
although you can let one mouse drink several beer in different time
table, but if the
What is the problem with sunny's solution ??
On Mon, Jun 20, 2011 at 9:31 AM, RAJAT kumar singh
rajat123si...@gmail.comwrote:
#includestdio.h
#includemath.h
char
s[]={'a','x','x','b','a','b','x','x','x','x','x','a','b','a','x','x','b',};
int minimum(char,char,int );
int main()
{
int
you can initialize it to (Max-Min+1)
where Max = max of all elements
Min = min of all elements
Or simple initialise it to a large integer like 0x7fff for 32 bit
numbers.
On Tue, Jun 28, 2011 at 3:32 PM, vikas mehta...@gmail.com wrote:
what will be the oldDiff initially. can u plz explain
Andres yes, I also think so. We will end up using 5 mice.
On Tue, Jun 28, 2011 at 3:54 PM, Anders Ma xuejiao...@gmail.com wrote:
I think the answer is 5.
To know which one is poisonous, you have to use one mouse.
How to use 3 mice achieve this goal?
If all the 3 mice drink the poisonous
Hey
The question I am currently working on is
http://www.spoj.pl/problems/MAIN8_D/
Actually I am unable to understand how the answer for HTHT is 20. I know
that the worst case for a string of 4 coin tosses should be 16*4. But how
the expected value is 20?
Can anyone explain?
Thanks
--
You
Can you please explain how to solve the 2nd question?
--
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/-/5C-1NnideVgJ.
To post to this group, send email to
@Ankit
Can you please explain the method to get the answer to the second subpart of
your solution in O(n) time?
My solution to solve the problem in O(n log(n)) time is as follows:
Insert the nodes of the sorted array into a binary tree. Then start with the
first node. Subtract the value of the
Well can anyone pls re post the problem?
On Tue, Jun 28, 2011 at 3:20 PM, kartik sachan kartik.sac...@gmail.comwrote:
@ vaibhav i have submitted my concept in spoj and it got AC in .02 sec
i am saying for u have to play with index of EITHER of G or B
now u have to think logic by taking two
@ankit : I'm pretty confident that the second part of your solution cannot
be done in O(n) time. Correct me if I am wrong!! Nevertheless, the overall
time complexity remains O(n*log(n)), as you pointed out.
On Tue, Jun 28, 2011 at 5:59 PM, Shachindra A C sachindr...@gmail.comwrote:
@Ankit
Can
@Shachindra
If you are using binary tree then why are you doing sorting first?
@ANKIT
Yes you can't do searching of sum of two numbers in less then O(n*n).
On Tue, Jun 28, 2011 at 6:23 PM, Shachindra A C sachindr...@gmail.comwrote:
@ankit : I'm pretty confident that the second part of your
http://www.spoj.pl/problems/SHLIGHTS/
this is the link
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
2nd part of ankit's solution can be easily done in O(n)
after sorting of array
i = 0, j = n-1
while(i j)
if a[i]+a[j] == x , i and j are indexes of the elements
if a[i]+a[j] x decrement j
if a[i]+a[j] x increment i
On Tue, Jun 28, 2011 at 6:49 PM, Shachindra A C sachindr...@gmail.comwrote:
http://www.se.cuhk.edu.hk/~seem3570/12-pattern.pdf
On Tue, Jun 28, 2011 at 5:26 PM, Nitish Garg nitishgarg1...@gmail.comwrote:
Hey
The question I am currently working on is
http://www.spoj.pl/problems/MAIN8_D/
Actually I am unable to understand how the answer for HTHT is 20. I know
that the
@Shachindra: The second part of my solution can definitely be done in
O(n) time . Take 2 pointers : one pointing to the start of the array
and the second pointing to the end of the array. If sum of these 2 is
less than the required sum, increment the first pointer else increment
the second pointer
For the second question have a stack as usual, but have a pointer for
each stack entry. Have a head pointer which points to the minimum.
These pointers point in the sorted order. This is explained by the
following example.
Suppose the elements are pushed in the following order : 3,6,1,8,2.
Then
Improvement of my solution to second question :
Instead of forming a linked list ,take a heap of the pointer of all
elements in the stack. Apply min heapify to the heap using value to
which the pointer points as the key.
Clearly getMinElement() O(1)
ohh its a straight chain..nt a rounded one..
gt it
On Tue, Jun 28, 2011 at 12:42 PM, sagar pareek sagarpar...@gmail.comwrote:
@amit
Check out your IQ
On Tue, Jun 28, 2011 at 2:43 AM, amit kumar amitthecoo...@gmail.comwrote:
how 2??
On Tue, Jun 28, 2011 at 2:40 AM,
Can somebody give a link to a good tutorial on expected values,which can be
used to solve this kind of problems,
(One of the links from which I have already read is
http://www.codechef.com/wiki/tutorial-expectation,though it did not help
much)
On Tue, Jun 28, 2011 at 7:06 PM, anubhav gupta
Sunny, the solution is great. Could you give me some ideas around how
do you approach such problems in recursive manner?
Recursion is never easy for me to understand as it is difficult to visualize.
On Tue, Jun 21, 2011 at 11:52 PM, sunny agrawal sunny816.i...@gmail.com wrote:
see this
http://en.wikipedia.org/wiki/List_of_algorithms
How many do you know? :)
--Navneet
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
The page is too long to read :P :P
On Tue, Jun 28, 2011 at 9:45 PM, Navneet Gupta navneetn...@gmail.comwrote:
http://en.wikipedia.org/wiki/List_of_algorithms
How many do you know? :)
--Navneet
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks
There is one way in which we can do O(n).
Convert the numbers in base 'n'. [ O(n) ].
Now, there are 2-digit numbers, each digit ranging from 0 to n-1.
You can call count-sort 2 times (for each digit), so, complexity is O(n
+n) =O(n).
On Jun 27, 12:22 am, Dan dant...@aol.com wrote:
Your question
20% of those :)
On Tue, Jun 28, 2011 at 9:47 PM, piyush kapoor pkjee2...@gmail.com wrote:
The page is too long to read :P :P
On Tue, Jun 28, 2011 at 9:45 PM, Navneet Gupta navneetn...@gmail.comwrote:
http://en.wikipedia.org/wiki/List_of_algorithms
How many do you know? :)
--Navneet
O(lglgn) :)
On Tue, Jun 28, 2011 at 10:52 PM, rajeev bharshetty rajeevr...@gmail.comwrote:
20% of those :)
On Tue, Jun 28, 2011 at 9:47 PM, piyush kapoor pkjee2...@gmail.comwrote:
The page is too long to read :P :P
On Tue, Jun 28, 2011 at 9:45 PM, Navneet Gupta
lol... unfortunately i gave the same answer, and they told me to try my luck
at google..
Regards,
Priyanshu Gupta
On Tue, Jun 28, 2011 at 10:42 AM, pacific :-) pacific4...@gmail.com wrote:
Brin and Larry would be the best people to answer this question.
On Tue, Jun 28, 2011 at 12:10 AM,
I think this is also a compiler dependent program..
Bcz if u run d code
#includestdio.h
typedef struct
{
char *name;
double salary;
}job;
main()
{
static job a={tcs,15000.0};
static job a={ibm,25000.0};
static job a={google,35000.0};
int x=5;
job *arr[3]={a,b,c};
@vaibhav agarwal: case 3 of urs gives ans 6 according to ur algo, but
the correct ans is 5
also the following test case also gives wrong ans with ur algo :
GBBGBBBB
Ur algo give - 9
Correct ans-- 7
--
You received this message because you are subscribed to the Google
http://www.spoj.pl/problems/GPA1/
hey guys here is my code and its given WA ...plzz tell me
where i am worng..i am tried getting WA in this question
# includestdio.h
# includestdlib.h
int main()
{
int n;
scanf(%d,n);
while(n--)
{
double a,b,c,d,e,f;
double
if u want code then mail me.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
AMIT TWO IN CASE OF ONLY 2 PIECES ARE TO BE JOINED.
ANSWER IS 4 AS U CAN CALCULATE I GUESS TO MAKE A STRAIGHT CHAIN FROM 3
BROKEN PIECES.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
@sagar : it works perfectly fine.
On Tue, Jun 28, 2011 at 3:29 PM, sagar pareek sagarpar...@gmail.com wrote:
Check out my solution above :)
Its reversing the string
On Tue, Jun 28, 2011 at 1:56 PM, shady sinv...@gmail.com wrote:
no, you arent actually reversing anything, you are just
#includestdio.h
int main()
{
int array[] = {23,34,12,17,204,99,16};
int TOTAL_ELEMENTS =(sizeof(array) / sizeof(array[0]));
int d;
for(d=-1;d = (TOTAL_ELEMENTS-2);d++)
printf(%d\n,array[d+1]);
return 0;
}
but in this case we are getting the same o/p..can u please again explain
whats wrong with
:))
On 28 June 2011 23:27, Priyanshu priyanshuro...@gmail.com wrote:
lol... unfortunately i gave the same answer, and they told me to try my
luck at google..
Regards,
Priyanshu Gupta
On Tue, Jun 28, 2011 at 10:42 AM, pacific :-) pacific4...@gmail.comwrote:
Brin and Larry would be
can nyone xplain me dt whats d meaning of (null) in d output...cz m getting
(null) 0.0 for d abv ques
On Fri, Jun 24, 2011 at 8:41 PM, oppilas . jatka.oppimi...@gmail.comwrote:
Please see this.
http://ideone.com/ZM74d
http://ideone.com/ZM74dI tried to print by directly giving 2[*arr]
@Ashish - If we have 2 stacks of length 'x' each, won't we be able to
enqueue 'x' elements?
On Jun 27, 10:39 pm, Ashish Goel ashg...@gmail.com wrote:
Hi,
The implementation is simple using 2 stacks, however we also need to make
sure that if queue length is say x, we are able to enqueue x
sanket, if 2 stacks r of length x, then2x elements should be nqed
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Wed, Jun 29, 2011 at 4:14 AM, Sanket vasa.san...@gmail.com wrote:
@Ashish - If we have 2 stacks of length 'x' each, won't we be
its tryin to acess arr[3] which is not defined and nullhence it is
giving null and priniting default value 0.000.arr[2[ is only the last
defined array of structure.
On Tue, Jun 28, 2011 at 12:07 PM, udit sharma sharmaudit...@gmail.comwrote:
I think this is also a compiler dependent
Suppose after first iteration, I iterate through whole array XORring+(1..N)
the last bit and I get 1.
Now, for making sure I don't need process undesirable numbers with last bit
'0', I will need to use sum bool array of size N bits to discard those
numbers or I can do it without using it?
pointer to next smallest will not lead to constant time operation
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
On Tue, Jun 28, 2011 at 3:19 PM, Anurag Sharma anuragvic...@gmail.comwrote:
for second problem, you can create a stack of having
We are getting same output because in this problem we wre typecastin
unsigned integer to a signed integer...Hence normal operation results.
On 6/28/11, Kamakshii Aggarwal kamakshi...@gmail.com wrote:
#includestdio.h
int main()
{
int array[] = {23,34,12,17,204,99,16};
int TOTAL_ELEMENTS
@ankit,sunny : thanks for the explanation. I got it.
On Wed, Jun 29, 2011 at 10:16 AM, Ashish Goel ashg...@gmail.com wrote:
pointer to next smallest will not lead to constant time operation
Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652
---
Aman (neshu) Agarwal wants to stay in better touch using some of
Google's coolest new
products.
If you already have Gmail or Google Talk, visit:
http://mail.google.com/mail/b-b44710bddc-6a8c132f56-rQdKCSY2nabAxzXd7j0SkQwzBZI
@Sanket: You are wrong. Let T(n) be the time to solve the problem of
size n. Then T(n) satisfies a recurrence T(n) = n + T(n/2). That is
because after you have done n reads, you have determined whether the
last bit is 0 or 1. To continue the solution, you only need to
consider those numbers that
77 matches
Mail list logo