[algogeeks] Re: NVIDIA Q

2011-07-07 Thread shiv narayan
it would be size of int. On Jul 7, 10:34 am, oppilas . jatka.oppimi...@gmail.com wrote: Ok. So for differentiating objects, we have size 1. What will be size of following class:- class A{      int z;}; How does different objects gets differentiated in above case? On Wed, Jul 6, 2011

Re: [algogeeks] MS Question

2011-07-07 Thread pacific :-)
Hi, You may look out for plagirism detectors. My approach would be : 1. Hash all the keywords in one file and keep the count. 2. For each keyword in the other file , check if it exists in the hash table , decrement its count. Also increment a counter which represents the similarity between the

Re: [algogeeks] solve this

2011-07-07 Thread rajeev bharshetty
93747 x^2+2x-15=0 roots are x=3 and x=-5 equations being 5digits (x^2) (x) (y) (x+1) (y1) y+y1=14 x+y=10 x=3 Solving these we get 93747 Regards Rajeev On Wed, Jul 6, 2011 at 7:35 PM, Anika Jain anika.jai...@gmail.com wrote: 93747 On Wed, Jul 6, 2011 at 5:05 AM, anurag aggarwal

Re: [algogeeks] Re: Complexity QuickSort

2011-07-07 Thread pacific :-)
Another question reg. quicksort. If we always find the median in o(n) and use it as the pivot ,will the quicksort by o(nlogn) ( i mean worst case also o(nlogn) )? Since partition is anyway o(n) , im making it o(n) + o(n){for finding median}. On Wed, Jul 6, 2011 at 2:50 AM, Ritesh Srivastava

Re: [algogeeks] Re: Random Number Generator

2011-07-07 Thread DeVaNsH gUpTa
I gave this method as you are also expecting random(0,1) to give values either 0 or 1 only, not between these two. Thanks and Regards Devansh Gupta MNNIT, Allahabad -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Piyush Sinha
@Navneettake a look at the solution below and tell if there is any bug in it... *#include string.h typedef struct revll { char s[100]; struct revll *next; }revll; revll *rev_str(char *a) { char temp[100]; int i,len=strlen(a),j=0; revll *head,*p;

Re: [algogeeks] Re: Random Number Generator

2011-07-07 Thread Nitish Garg
Yes, Random(0, 1) gives values 0 or 1 only with equal probabilities. But your solution won't work. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

[algogeeks] apti Q

2011-07-07 Thread Agyat
a clock gains uniformly and is 5 minute at 8.00 am on sunday.And on next sunday it is 5 minute 48 second fast at 8.00 pm.Tell the time when clock was showing correct time -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group,

[algogeeks] Amazon

2011-07-07 Thread Akshata Sharma
There is a straight roads with 'n' number of milestones. You are given an array with the distance between all the pairs of milestones in some random order. Find the position of milestones. Example: Consider a road with 4 milestones(a,b,c,d) : a --- 3Km ---b--- 5Km ---c--- 2Km ---d Distance between

Re: [algogeeks] Amazon

2011-07-07 Thread Piyush Sinha
I think for initial start it should be the minimum n values for n milestones On Thu, Jul 7, 2011 at 1:53 PM, Akshata Sharma akshatasharm...@gmail.comwrote: There is a straight roads with 'n' number of milestones. You are given an array with the distance between all the pairs of milestones

Re: [algogeeks] Amazon

2011-07-07 Thread Piyush Sinha
But the problem arises in setting the order On Thu, Jul 7, 2011 at 2:06 PM, Piyush Sinha ecstasy.piy...@gmail.comwrote: I think for initial start it should be the minimum n values for n milestones On Thu, Jul 7, 2011 at 1:53 PM, Akshata Sharma

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Vishal Thanki
Off Topic: Sorry for the diversion, but I was just wondering how easy it has become to code in languages other than c. Here is the code i wrote for the above mentioned problem in Python. It takes command line arg as string. something like vishal@ubuntu:~/progs/python\ 02:45:07 PM $ cat rev.py

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Navneet Gupta
@Vishal, can you see if your program works well for more than single space between words? Not sure how split functions helps. BTW, Perl also is very strong language for string manipulations. (Specially designed for efficient string operations) On Thu, Jul 7, 2011 at 2:48 PM, Vishal Thanki

Re: [algogeeks] Amazon

2011-07-07 Thread Navneet Gupta
Can we do this? Start with a node, take an edge say between x1 and x2 of length k1. Take another node x3 and check distance between x1 and x3 (k13) and x2 and x3 (k23) Depending on whether k13 or k23 is bigger, the node x3 between x1 and x2 or away from x1 and after x2. Proceeding in this way

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Vishal Thanki
@Navneet, it works with multiple spaces between words.. And here is the two line solution :) import sys print .join((sys.argv[1].split())[::-1]) On Thu, Jul 7, 2011 at 3:12 PM, Navneet Gupta navneetn...@gmail.com wrote: @Vishal, can you see if your program works well for more than single

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Navneet Gupta
@Vishal, Don't confuse printing in reverse with actually modifying the actual string to reverse word order in it :) On Thu, Jul 7, 2011 at 3:34 PM, Vishal Thanki vishaltha...@gmail.com wrote: @Navneet, it works with multiple spaces between words.. And here is the two line solution :) import

Re: [algogeeks] Re: Random Number Generator

2011-07-07 Thread surender sanke
if b-a is exactly 2^k-1 , k0 then a + k bits (each bit is set using rand(0 1) ) with equal probability surender On Thu, Jul 7, 2011 at 1:20 PM, Nitish Garg nitishgarg1...@gmail.comwrote: Yes, Random(0, 1) gives values 0 or 1 only with equal probabilities. But your solution won't work. -- You

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Vishal Thanki
yea, expression .join((sys.argv[1].split())[::-1]) will return the string!! On Thu, Jul 7, 2011 at 3:36 PM, Navneet Gupta navneetn...@gmail.com wrote: @Vishal, Don't confuse printing in reverse with actually modifying the actual string to reverse word order in it :) On Thu, Jul 7, 2011 at

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Vishal Thanki
#!/usr/bin/python import sys string=sys.argv[1] string= .join((string.split())[::-1]) print string How does this sound? :P On Thu, Jul 7, 2011 at 3:43 PM, Vishal Thanki vishaltha...@gmail.com wrote: yea, expression   .join((sys.argv[1].split())[::-1]) will return the string!! On Thu, Jul 7,

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Navneet Gupta
I meant, having the result in same string which was used as param. Is that the case? I think the below will use a separate string. On Thu, Jul 7, 2011 at 3:43 PM, Vishal Thanki vishaltha...@gmail.com wrote: yea, expression   .join((sys.argv[1].split())[::-1]) will return the string!! On

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Navneet Gupta
Okay, I think NO EXTRA SPACE is what i should have mentioned clearly. Anyways dude, i appreciate the point of simplicity which you are trying to show. On Thu, Jul 7, 2011 at 3:45 PM, Navneet Gupta navneetn...@gmail.com wrote: I meant, having the result in same string which was used as param. Is

Re: [algogeeks] Amazon

2011-07-07 Thread Sandeep Jain
How about this?? Since we have the distances between all pairs of nodes, so first we find the largest distance. They nodes which are the maximum distance are terminal nodes. So in the given e.g. we get a-d at a distance of 10 units. Now with this we know that the remaining nodes will lie between

[algogeeks] Re: Amazon

2011-07-07 Thread Gaurav Tyagi
How about this ? 1. We construct a graph with these nodes. 2. We make an incoming edge on a node if it is created using some other node. Ex: 7=5+2. So 7 will have 1 incoming and 5 2 will have outgoing. 3. Select all the nodes which only have outgoing edges. These would be the actual distances

[algogeeks] Re: Random Number Generator

2011-07-07 Thread Nitish Garg
Thanks Dave, nice solution. By setting the bits we can get equal probabilities. -- 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/-/Y02NVHYBhdkJ. To post to

[algogeeks] Re: Bipartite Matching?

2011-07-07 Thread bittu
@nishit whats the problem with Bipartite Matching ist perfect example of Bipartite Graph isn't it ?? as have to just divide the set of vertex in to two disjoint set such that no two people who are friends will be in same team that what Bipartite Matching says ?? although graph coloring will also

Re: [algogeeks] apti Q

2011-07-07 Thread Tushar Bindal
the clock has become faster by 48 seconds in 10800 minutes i.e., 1 sec in 225 minutes from 8am on sunday we have to go 225*5*60 minutes behind to get time when clock showed the correct time. i.e., 67500 minutes or 44 days 1260 minutes 44 days 21 hours which means clock showed correct timing at

Re: [algogeeks] Re: Amazon

2011-07-07 Thread sachin sharma
What about this: First you have the list of distances between two milestones. Let’s form a table Start milestone End Milestone Distances A1 A0 7 A0 A3 10 A1 A2 5 A2 A3 2 A0 A2 8 A0 A1 3 I have taken above variable A0, A1, A2, A3 for a, b, c, d respectively. Now we sort the

Re: [algogeeks] NVIDIA Q

2011-07-07 Thread T3rminal
struct t{}; int main(){ struct t a,b,c; int l; printf(%u %u %u %u\n,a,b,c,l); } o/p 3213845680 3213845680 3213845680 3213845676 a,b,c all are pointing to same location, so no space is allocated to them. As i already mentioned, *may be* . I dont know what standard says about it or rather i

[algogeeks] Re: Amazon

2011-07-07 Thread Dumanshu
how about this? given n milestones 1.find max number from the array and delete it. 2.now find any (x,y) both from the array such that x+y == max. 3. put min(x,y) in the front of output array, delete y from array and if(sizeof(output array)==(n-2)) put x also in front of output array and

[algogeeks] Re: Amazon

2011-07-07 Thread Dumanshu
Initially we can sort the array in O(nlogn) and then given a max value, find a pair (x,y) in O(n). here n is also of quadratic order if taken in terms of no. of milestones. On Jul 7, 5:52 pm, Dumanshu duman...@gmail.com wrote: how about this? given n milestones 1.find max number from the

[algogeeks] Dynamic Programming

2011-07-07 Thread Rakib Ansary Saikot
Heres a problem that I've been trying to solve using Dynamic Programming but I've got no where with it. Any hints would be appreciated. A program's library offers a simple function to split a string into two parts. As this operation requires copying the entire string, it takes time n, where n is

Re: [algogeeks] Re: Amazon

2011-07-07 Thread Swathi
My solution, a) First sort the distances. b) We will consider the first 2 minimum numbers.. They are definitely the distances between the 3 nodes... c) Find the sum of the first 2 minimum numbers.. If this sum is outside n then we simply return all the nodes less than n else remove that sum and

Re: [algogeeks] Re: Amazon

2011-07-07 Thread Swathi
My solution, a) First sort the distances. b) We will consider the first 2 minimum numbers.. They are definitely the distances between the 3 nodes... c) Find the sum of the first 2 minimum numbers.. If this sum is outside n then we simply return all the nodes less than n else remove that sum and

Re: [algogeeks] Re: Amazon

2011-07-07 Thread yv paramesh
Hi, a --- 3Km ---b--- 5Km ---c--- 2Km ---d--- 6Km --e lets arry be 3,5,2,6,8,10,16,7,13,8it can be any order... higest value is 16 ie total distance. now chose pairs whose sum equals to 16 3,13 6,10 8,8 now we come to know the distance of point for either from a or e If we are able to

Re: [algogeeks] Re: Amazon

2011-07-07 Thread Swathi
This will take more time than mine... Mine will be very fast as we are exiting if the least sum is outside n On Thu, Jul 7, 2011 at 6:56 PM, yv paramesh yv.param...@gmail.com wrote: Hi, a --- 3Km ---b--- 5Km ---c--- 2Km ---d--- 6Km --e lets arry be 3,5,2,6,8,10,16,7,13,8it can be any

Re: [algogeeks] Re: Puzzle

2011-07-07 Thread swetha rahul
Got it...Thanks.. On Wed, Jul 6, 2011 at 11:31 PM, shiv narayan narayan.shiv...@gmail.comwrote: speed of river=(distance traveled by object in it) / total time it took to travel here hat has traveled a distance of 1 KM and it has taken =5mn+5 min=10 min=10min/60=1/6 hrs; so speed =

[algogeeks] Puzzle

2011-07-07 Thread swetha rahul
At a movie theater, the manager announces that they will give a free ticket to the first person in line whose birthday is the same as someone who has already bought a ticket. You have the option of getting in line at any time. Assuming that you don't know anyone else's birthday, that birthdays are

[algogeeks] Re: Puzzle

2011-07-07 Thread Gaurav Tyagi
The greatest chance i.e. 100% chance would be at position number 366. (By Pigeonhole principle). On Jul 7, 2:34 pm, swetha rahul swetharahu...@gmail.com wrote: At a movie theater, the manager announces that they will give a free ticket to the first person in line whose birthday is the same as

[algogeeks] Re: Longest substring 0's 1's

2011-07-07 Thread yogi
I have one more approach in mind where it requires T(n) = O(n) and O(1) space complexity. here it goes: 1) Start traversing the array. 2)Store the location when 0 and 1 both appears for the first time in some variable. 3)Similarly store the location of 0 and 1 when both appears for the last time

Re: [algogeeks] Re: Some adobe interview questions.

2011-07-07 Thread Yogesh Yadav
Q10. array a[]={19 16 18 3 50 70 12 11 14} array b[]; sum required=30 3 11 12 14 16 18 19 50 70 //sort 0 1 2 3 4 5 6 7 8 //index lr count=0,i=0; while(lr) { if(a[l]+a[r])sum r--; elseif(a[l]+a[r])sum l++; else {

Re: [algogeeks] Re: Some adobe interview questions.

2011-07-07 Thread raj singh
thanks yogi. it is amzing tric and solution -- 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

Re: [algogeeks] Re: Some adobe interview questions.

2011-07-07 Thread Yogesh Yadav
Q3. start with 7000 //8 digit number 7000 7001 //as 7 is 1 time so 8th place is 1 6001 //as due to 1 on 8th place no. of zeros =6 6010 //as 6 is present so 7th place is 1 and 7 is not present so 8th place is again changed to 0 6110 //as 1 is present on 7th place so at 2nd

Re: [algogeeks] Re: Puzzle

2011-07-07 Thread Tushar Bindal
probability that i win standing at second position: 1/365 third position : 364/365*2/365 = 1/365)*(628/365) fourth position : 364/365*363/365*3/365 4th : 364/365*363/365*362/365*4/365 nth position: (365-1)*(365-2)*(365-3)*(365-4)*(365-5).*(365-(n-2))*(365-(n-1))*(n)*(1/365)^n -- You

[algogeeks] Re: Unique substring

2011-07-07 Thread Ankur
Akash johari : can you tell me the way to create suffix tree in o(n) time ? i know only nlogn (also n*logn^2) method . If not , how can you do it in o(n) ? @ hemeesh : Also how can KMP be useful to solve it ? On Jul 6, 8:25 pm, Hemesh Singh hemesh.mn...@gmail.com wrote: I think this problem

Re: [algogeeks] Re: Puzzle

2011-07-07 Thread Tushar Bindal
Sorry for the previous post the last line was incorrect it should have been (n+1)th position I was just writing roughly and pressed send instead of save. -- 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: Puzzle

2011-07-07 Thread Tushar Bindal
probability that i win standing at second position: 1/365 probability that i win standing at third position : 364/365*2/365 = 1/365)*(628/365) probability that i win standing at fourth position : 364/365*363/365*3/365 probability that i win standing at 4th position : 364/365*363/365*362/365*4/365

Re: [algogeeks] Re: Amazon

2011-07-07 Thread Sandeep Jain
@Sachin: What if the milestones were, A1-A3-A2-A0 in this order? Regards, Sandeep Jain On Thu, Jul 7, 2011 at 6:00 PM, sachin sharma sachin.bles...@gmail.comwrote: What about this: First you have the list of distances between two milestones. Let’s form a table Start milestone End

Re: [algogeeks] Re: Amazon

2011-07-07 Thread Sandeep Jain
@Sachin: What if the milestones were, A1-A3-A2-A0 in this order? Regards, Sandeep Jain On Thu, Jul 7, 2011 at 6:00 PM, sachin sharma sachin.bles...@gmail.comwrote: What about this: First you have the list of distances between two milestones. Let’s form a table Start milestone End

[algogeeks] Re: DP or DFS

2011-07-07 Thread KK
Can u elaborate something on implementation.?? -- 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

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Piyush Kapoor
char a[20]; int l; int main() { char str[100]; scanf(%s,str); l=strlen(str); } -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- 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] Reversing the order of words in String

2011-07-07 Thread Piyush Kapoor
Pls Ignore my above post.. On Thu, Jul 7, 2011 at 10:36 PM, Piyush Kapoor pkjee2...@gmail.com wrote: char a[20]; int l; int main() { char str[100]; scanf(%s,str); l=strlen(str); } -- *Regards,* *Piyush Kapoor,* *CSE-IT-BHU* -- *Regards,* *Piyush Kapoor,*

Re: [algogeeks] Re: Amazon

2011-07-07 Thread durgesh kumar
step:- 1) sort the array 2) remove the smallest and largest element from arary. keep the smallest elemnt in seperate queue(result) 3) repeat the above untill the array is empty or it contains only it contains only one element 4) put the last element also in the queue (result) eg:-for ur example

Re: [algogeeks] Re: Amazon

2011-07-07 Thread Swathi
No need.. check my solution... On Thu, Jul 7, 2011 at 10:39 PM, durgesh kumar durgesh1...@gmail.comwrote: step:- 1) sort the array 2) remove the smallest and largest element from arary. keep the smallest elemnt in seperate queue(result) 3) repeat the above untill the array is empty or it

Re: [algogeeks] Re: Amazon

2011-07-07 Thread durgesh kumar
On Thu, Jul 7, 2011 at 6:41 PM, Swathi chukka.swa...@gmail.com wrote: My solution, a) First sort the distances. b) We will consider the first 2 minimum numbers.. They are definitely the distances between the 3 nodes... c) Find the sum of the first 2 minimum numbers.. If this sum is outside

Re: [algogeeks] Re: Amazon

2011-07-07 Thread durgesh kumar
On Thu, Jul 7, 2011 at 4:15 PM, Gaurav Tyagi cho...@gmail.com wrote: How about this ? 1. We construct a graph with these nodes. 2. We make an incoming edge on a node if it is created using some other node. Ex: 7=5+2. So 7 will have 1 incoming and 5 2 will have outgoing. 3. Select all the

Re: [algogeeks] Re: Amazon

2011-07-07 Thread Swathi
Why it will fail.. let the given sequence be : A-1--B---5---C--3-D-2-E A-B : 1 A -C : 6 A -D: 9 A-E : 12 B-C: 5 B-D: 8 B-E: 10 C-D: 3 C-E: 5 D-E: 2 When we sort we will get 1,2,3,5,5,6,8,9,10,12. The first 2 small number are 1 and 2... so out of 4 distances we

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Piyush Kapoor
char a[20]; int l,i,j,k; int main() { char str[100]; gets(str); l=strlen(str); for(i=l-1;i=0;){ k=19; a[k]='\0'; while(i=0 str[i]!=' '){ a[--k]=str[i--]; } printf(%s,a+k); while(i=0 str[i]==' ') i--; printf( ); } } On Thu, Jul 7, 2011 at

Re: [algogeeks] Re: Amazon

2011-07-07 Thread durgesh kumar
dear swathi, i m not geetint solution for this pexample according to your algo.cold u explain me wth this example ... A--1---B--5--C-3-D2E thanks in advance durgesh -- You

Re: [algogeeks] Re: Amazon

2011-07-07 Thread oppilas .
step:- 1) sort the array 2) remove the smallest and largest element from arary. keep the smallest elemnt in seperate queue(result) 3) repeat the above untill the array is empty or it contains only it contains only one element 4) put the last element also in the queue (result) eg:-for ur

Re: [algogeeks] Re: Amazon

2011-07-07 Thread sunny agrawal
@swathi i think your algo won't work try out for the following cases 1. 2,3,5,7,8,10 2. 2,3,5,6,9,11 On Thu, Jul 7, 2011 at 10:59 PM, oppilas . jatka.oppimi...@gmail.comwrote: step:- 1) sort the array 2) remove the smallest and largest element from arary. keep the smallest elemnt

Re: [algogeeks] Re: Amazon

2011-07-07 Thread durgesh kumar
sry it was mistyped -- 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

Re: [algogeeks] Re: Amazon

2011-07-07 Thread durgesh kumar
@swathi:- nice try bt could u explain for A1---B--6--C-3D--2E thanks Durgesh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

Re: [algogeeks] Re: Amazon

2011-07-07 Thread durgesh kumar
@oppilas:- yes U r right... i simply mistyped it...I think evrythng else is ok. thanks Durgesh -- 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

[algogeeks] Starting the journey

2011-07-07 Thread Puneet Gautam
Hi everyone... umm i am a bit new to algo applications in programming.. can anyone pls tell me what all is important in algorithms? ,From companies point of view... I have studied upto ch-13 of the book Cormen. Thanks.. -- You received this message because you are subscribed to the Google

Re: [algogeeks] puzzle

2011-07-07 Thread Sumit chauhan
The ans is 16 because :- if we drop from 16th floor and if egg1 breaks floor to be tested is b/w 1-16 . Then start from floor 1 with egg2 and floor from which it breaks first is obtained and will lie b/w 1-16. the attempts are no more than 16. however If egg1 doesn't break on 16 floor then try on

Re: [algogeeks] puzzle

2011-07-07 Thread Anurag atri
The answer is 14 . On Thu, Jul 7, 2011 at 11:25 PM, Sumit chauhan sumitchauhan...@gmail.comwrote: The ans is 16 because :- if we drop from 16th floor and if egg1 breaks floor to be tested is b/w 1-16 . Then start from floor 1 with egg2 and floor from which it breaks first is obtained and

Re: [algogeeks] Re: Amazon

2011-07-07 Thread Akshata Sharma
@durgesh, step:- 1) sort the array 2) remove the smallest and largest element from arary. keep the smallest elemnt in seperate queue(result) 3) repeat the above untill the array is empty or it contains only it contains only one element 4) put the last element also in the queue (result) for

Re: [algogeeks] puzzle

2011-07-07 Thread Tushar Bindal
Sumit, the answer is 14 I think the example of 16 that they take on careerplus is probably confusing you. -- 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

[algogeeks] GOOGLE Q1

2011-07-07 Thread Piyush Sinha
Given an array of integers A, give an algorithm to find the longest Arithmetic progression in it, i.e find a sequence i1 i2 … ik, such that A[i1], A[i2], …, A[ik] forms an arithmetic progression, and k is the largest possible. The sequence S1, S2, …, Sk is called an arithmetic progression if

[algogeeks] GOOGLE Q2

2011-07-07 Thread Piyush Sinha
Design a data structure that can be used instead of an array and avoids the high-cost (i.e. O(n)) of initializing the array. the data structure ought to holds n items and supports the following operations in O(1) time: * Init – Initializes the data structure to empty. * Set(i, x) – Sets item x at

Re: [algogeeks] Re: Puzzle

2011-07-07 Thread Tushar Bindal
Sory once again for that incomplete answer. The complete one is here. probability that i win standing at second position: 1/365 probability that i win standing at third position : 364/365*2/365 = 1/365)*(628/365) probability that i win standing at fourth position : 364/365*363/365*3/365

[algogeeks] Merging Sorted Arrays

2011-07-07 Thread radha krishnan
:Given two sorted arrays a[]={1,3,77,78,90} and b[]={2,5,79,81}. Merge these two arrays, no extra spaces are allowed. Output has to be a[]={1,2,3,5,77} and b[]={78,79,81,90}. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] Re: puzzle

2011-07-07 Thread Sumit chauhan
Ans :- 3 let bottles be1,2,3,4,5,6 and mice be a,b,c. separate bottle 6 make pairs P(1,2,3) ; Q(2,4) ; R(3,4,5) and given to mice a,b,c resp. if poison is inbottle mice who dies 1 a 2 a,b 3

Re: [algogeeks] puzzle

2011-07-07 Thread Sumit chauhan
@ Tushar the answer is 16 and i have proved it. if it is 14 , then prove 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

Re: [algogeeks] GOOGLE Q1

2011-07-07 Thread rajeev bharshetty
Check the differences between the adjacent elements and store the differenecs in diff[i] array then scan through the array . then keep a count for all the repeated diff elements ,the sequence of indexes with max count is the solution . On Thu, Jul 7, 2011 at 11:43 PM, Piyush Sinha

Re: [algogeeks] puzzle

2011-07-07 Thread sunny agrawal
@Sumit lets consider the case the Egg does not break even from 100th floor in your case u will get to know the answer in 8th trial.after 91 trying from 100 but worst case solution is 16 for your solution. we can do better by starting at 14 as above explained

Re: [algogeeks] GOOGLE Q1

2011-07-07 Thread sunny agrawal
@rajiv Fails i think think for 10 12 24 26 diff is 2 12 2 so do you want to say there is an AP pf 3 elements with d = 2, i can't see any :P your solution fails because there can be many APs in the array with the same value of d and you will finish up by combining all those APs On Fri,

Re: [algogeeks] puzzle

2011-07-07 Thread Sumit chauhan
@sunny dude i got so excited after finding this solution i did not bother to check for 14 -- 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

Re: [algogeeks] GOOGLE Q3

2011-07-07 Thread rajeev bharshetty
So, I think first check for excellent groups then good and then usual to increase the quality. So to get excellent groups scan the string and keep a count of the contagious repeating elements ,if count==3 or count==2,then put in one group The same procedure for good and usual accord to constraints

Re: [algogeeks] GOOGLE Q1

2011-07-07 Thread sunny agrawal
@rajiv if Count = 2 means 3 elements isn't it a,a+d,a+2d else according to you for case 10 12 14 24 26 28 diff 2 2 10 2 2 diff 2 has count 4 so will you say ap of 4 elements with diff 2 On Fri, Jul 8, 2011 at 1:06 AM, rajeev bharshetty rajeevr...@gmail.comwrote: @sunny Keep count of

Re: [algogeeks] GOOGLE Q1

2011-07-07 Thread rajeev bharshetty
Should the sequence beContinuos ??? On Fri, Jul 8, 2011 at 1:18 AM, sunny agrawal sunny816.i...@gmail.comwrote: @rajiv if Count = 2 means 3 elements isn't it a,a+d,a+2d else according to you for case 10 12 14 24 26 28 diff 2 2 10 2 2 diff 2 has count 4 so will you say ap of 4

Re: [algogeeks] Merging Sorted Arrays

2011-07-07 Thread Piyush Sinha
@radha...i have an algo but its complexity is O(n^2)...check the following and see if there is any bug as I havent tested for all cases...also suggestions are welcomed:) main() { int a[]= {1,3,77,78,88}; int b[]= {2,5,79,80,81,99}; int i=sizeof(a)/sizeof(a[0]) - 1; int

Re: [algogeeks] Merging Sorted Arrays

2011-07-07 Thread radha krishnan
ok ! i got a O(n lgn) finally i don know exact complexity Let N = size of first array Find the first N smallest elements using one pointer in each array now swap the list of elements from index 0 to second-pointer in second array to first array with first_poiner+1 to N in first Array I think this

Re: [algogeeks] GOOGLE Q3

2011-07-07 Thread Piyush Sinha
@Rajeev...check ur logic for 4 On 7/8/11, rajeev bharshetty rajeevr...@gmail.com wrote: So, I think first check for excellent groups then good and then usual to increase the quality. So to get excellent groups scan the string and keep a count of the contagious repeating elements ,if

Re: [algogeeks] GOOGLE Q1

2011-07-07 Thread Piyush Sinha
Nopesits about finding subsequence On 7/8/11, rajeev bharshetty rajeevr...@gmail.com wrote: Should the sequence beContinuos ??? On Fri, Jul 8, 2011 at 1:18 AM, sunny agrawal sunny816.i...@gmail.comwrote: @rajiv if Count = 2 means 3 elements isn't it a,a+d,a+2d else according to

[algogeeks] Re: GOOGLE Q3

2011-07-07 Thread Yuduo Zhou
Given 77, it can be divided into 77-77-77 or 777-777 so it will return 77-77-77 with a quality of 6, other than the other way, which gives quality of 4. Also , a good group like 229, can be seen as 22-9, which gives a excellent group. I assume first looking groups with 2 digits? On Jul 7,

Re: [algogeeks] Merging Sorted Arrays

2011-07-07 Thread sunny agrawal
yes upto the step of swapping the elements it is O(m+n) but if you need final arrays also sorted (Seems like that from your first post)it will go nlgn On Fri, Jul 8, 2011 at 1:25 AM, radha krishnan radhakrishnance...@gmail.com wrote: ok ! i got a O(n lgn) finally i don know exact

Re: [algogeeks] GOOGLE Q3

2011-07-07 Thread rajeev bharshetty
It scans 555 count=3(excellent group) it will put in one group than 54 since the count is one puts that in usual group quality =2*1 =2 , On Fri, Jul 8, 2011 at 1:28 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote: @Rajeev...check ur logic for 4 On 7/8/11, rajeev bharshetty

Re: [algogeeks] Merging Sorted Arrays

2011-07-07 Thread Piyush Sinha
@RADHA..ya true...my bad i cudnt think dat way...but as pointed out by Sunny the sorted output cant be brought in O(n)...In order to get the sorted output only my algo took O(n^2)...tell me if I am missing anything... On 7/8/11, sunny agrawal sunny816.i...@gmail.com wrote: yes upto the step of

Re: [algogeeks] GOOGLE Q3

2011-07-07 Thread sunny agrawal
i think DP has answer to this question initialy compute the quality value of all the substrings of length 1,2,3 Ans[i][j] = max(ans[i,j-2]+ans[j-1][j],ans[i,j-3]+ans[j-2][j],ans[i,i+1]+ans[i+2][j],ans[i,i+2]+ans[i+3][j]) something like that. On Fri, Jul 8, 2011 at 1:31 AM, rajeev bharshetty

Re: [algogeeks] GOOGLE Q3

2011-07-07 Thread Piyush Sinha
@Rajeev..there is the fault.for 4, there can be 2 excellent groups.. 55 55 54 therefore, quality = 2*2 = 4 which is highest... On 7/8/11, rajeev bharshetty rajeevr...@gmail.com wrote: It scans 555 count=3(excellent group) it will put in one group than 54 since the count is one puts

Re: [algogeeks] GOOGLE Q3

2011-07-07 Thread Piyush Sinha
sorry a typing mistake...lst line contains only 4 On 7/8/11, Piyush Sinha ecstasy.piy...@gmail.com wrote: @Rajeev..there is the fault.for 4, there can be 2 excellent groups.. 55 55 54 therefore, quality = 2*2 = 4 which is highest... On 7/8/11, rajeev bharshetty

Re: [algogeeks] GOOGLE Q3

2011-07-07 Thread Piyush Sinha
@Rajeev...ignore my previous two posts. the grouping can be done as 55 554 quality is 2*1+1 = 3 which is the highest On 7/8/11, Piyush Sinha ecstasy.piy...@gmail.com wrote: sorry a typing mistake...lst line contains only 4 On 7/8/11, Piyush Sinha ecstasy.piy...@gmail.com wrote:

[algogeeks] Improve upon O(m^2)

2011-07-07 Thread Dumanshu
given two sorted arrays a[m] b[2*m], each contains m elements only. You need to merge those two arrays into second array b[2*m]. anything better than O(m^2) -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

[algogeeks] suffix tree algorithm

2011-07-07 Thread coder coder
how to make a sufffix tree with different complexities along with its uses -- 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] Re: Merging Sorted Arrays

2011-07-07 Thread Yuduo Zhou
I remember there is an swap using XOR that uses no extra space. It's also O(1). assume we have a O(1) function: swap(a, b) a[m], b[n], all sorted separately. for (i = 0; i m; i++){ if (a[i] b[0]){ swap(a[i], b[0]); if (b[0] b[1]){ swap(b[1], b[0]); }

Re: [algogeeks] GOOGLE Q3

2011-07-07 Thread Ravi Shukla
@sunny , yep it looks DP. more of MCM. solve for substrings of length 1,2,3. and then apply DP[i][j]=max score for a substring from i to j. =max(DP[i][k]+DP[k][j]) where ki kj . The complexity this approach renders would be O(n^3). with O(n^2) space complexity. anyone anything better ?

[algogeeks] Re: Merging Sorted Arrays

2011-07-07 Thread Yuduo Zhou
Yep, I was wrong. for (i = 0; i m; i++){ if (a[i] b[0]){ swap(a[i], b[0]); push b[0] to the end of array-b as far as possible here. } } Then it's not O(m+n) anymore. O(mn) instead. On Jul 7, 4:33 pm, Yuduo Zhou yuduoz...@gmail.com wrote: I remember there is an swap

Re: [algogeeks] GOOGLE Q3

2011-07-07 Thread Piyush Sinha
@Sunny...can u post a definite algo for it?? On 7/8/11, Ravi Shukla shuklaravi...@gmail.com wrote: @sunny , yep it looks DP. more of MCM. solve for substrings of length 1,2,3. and then apply DP[i][j]=max score for a substring from i to j. =max(DP[i][k]+DP[k][j]) where ki kj . The

Re: [algogeeks] Improve upon O(m^2)

2011-07-07 Thread sunny agrawal
O(m) is always better than O(m^2) :) :P Simple merge sort hint : start from end of the arrays select the text in white font to see the hint :) On Fri, Jul 8, 2011 at 1:56 AM, Dumanshu duman...@gmail.com wrote: given two sorted arrays a[m] b[2*m], each contains m elements only. You need to

  1   2   >