Re: [algogeeks] Re: Google Question--Suggest Algo

2011-11-28 Thread Nitin Garg
@Sourabh - whats the running time? On Mon, Nov 28, 2011 at 3:28 AM, Ankur Garg ankurga...@gmail.com wrote: Cool Solution...I was thinking of DP but wasnt clear on the recurrence... Nice thinking man and thanks :) On Mon, Nov 28, 2011 at 2:47 AM, sourabh sourabhd2...@gmail.com wrote:

[algogeeks] Number Theory (Power of 3 )

2011-11-28 Thread SAMMM
Given a number u have to check whether the number(N) can be expressed in the form 3^n = N i:e It can be expressed in terms of power of 3. It can be done taking log on both but I am looking an alternate approach (bit manipulation) . -- You received this message because you are subscribed to

[algogeeks] Number Theory (Power of 3 )

2011-11-28 Thread SAMMM
Given a Natural Number N , We hav to check whether it can be expressed in the form of 3^n =N . (0=nN) It can be done taking log , but i m looking for some Bit manipulation . -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] Re: Google Question--Suggest Algo

2011-11-28 Thread sourabh
O(N*K) On Nov 28, 1:04 pm, Nitin Garg nitin.garg.i...@gmail.com wrote: @Sourabh - whats the running time? On Mon, Nov 28, 2011 at 3:28 AM, Ankur Garg ankurga...@gmail.com wrote: Cool Solution...I was thinking of DP but wasnt clear on the recurrence... Nice thinking man and thanks

[algogeeks] Re: Google Question--Suggest Algo

2011-11-28 Thread Dumanshu
Hi I may not have understood your solution properly. But i think that your solution is an implementation of brute force where you are dealing with all cases valid in the range n/2k and 3n/2k without any optimization with regard to DP. Am i right? On Nov 28, 2:17 am, sourabh

Re: [algogeeks] Suggest Algo: OffCampus Apple Interview Question

2011-11-28 Thread Nitin Garg
Please clarify. Also tell offcampus interview for which company? On Mon, Nov 28, 2011 at 7:10 PM, Siddharth Pipriya sid@gmail.comwrote: write a program that takes as input a number x and gives output true x percent of the time it is run. -- You received this message because you are

Re: [algogeeks] Re: Linear time Binary tree re-construction

2011-11-28 Thread Nitin Garg
Lets say the in-order traversal is O = O1,O2,...On Pre-order is P = P1,P2,...Pn Lets assume that the in-order traversal gives sorted sequence of numbers. (if not, we can replace Pi by i in our algorithm and replace it to original later on) Observe P1 will be the root. If left subtree is not

Re: [algogeeks] Re: Linear time Binary tree re-construction

2011-11-28 Thread Nitin Garg
A[1,n,1,n] will give us the solution. On Mon, Nov 28, 2011 at 7:47 PM, Nitin Garg nitin.garg.i...@gmail.comwrote: Lets say the in-order traversal is O = O1,O2,...On Pre-order is P = P1,P2,...Pn Lets assume that the in-order traversal gives sorted sequence of numbers. (if not, we can

Re: [algogeeks]

2011-11-28 Thread Dave
@Kartik: That would be O(n), not o(n). Dave On Nov 27, 11:41 pm, kartik sachan kartik.sac...@gmail.com wrote: simply find max in o(n) by liner search then remove max then again find max that will be second max:P :P -- You received this message because you are subscribed to the Google

[algogeeks] Re: Google Question--Suggest Algo

2011-11-28 Thread sourabh
Yes nithin its O(n^2).. The reasoning being say, We store all the values in a 2-d array of size N * K. Now to compute each element of the above array , we are looking N/K (3n/2k - n/2k) sub problems.. Hence, the running time would be, O( N * K * N / K ) i.e O( N^2)... On Nov 28, 6:42 pm, Nitin

[algogeeks] Re: Google Question--Suggest Algo

2011-11-28 Thread sourabh
Yes nithin its O(n^2).. The reasoning being say, We store all the values in a 2-d array of size N * K. Now to compute each element of the above array , we are looking at N/ K (3n/2k - n/2k) sub problems.. Hence, the running time would be, O( N * K * N / K ) i.e O( N^2)... On Nov 28, 6:42 pm,

[algogeeks] Re: Google Question--Suggest Algo

2011-11-28 Thread sourabh
Yes nithin its O(n^2).. The reasoning being say, We store all the values in a 2-d array of size N * K. Now to compute each element of the above array , we are looking at N/ K (3n/2k - n/2k) sub problems.. Hence, the running time will be, O( N * K * N / K ) i.e O( N^2)... On Nov 28, 6:42 pm, Nitin

Re: [algogeeks]

2011-11-28 Thread kartik sachan
@DAVE that was typing mistake... -- 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] facebook interview question

2011-11-28 Thread Nitin Garg
Find the min and max in an array. Now do it in less than 2n comparisons. (they were looking for the solution that finds both max and min in about 3/2 n comparisons). -- Nitin Garg Personality can open doors, but only Character can keep them open -- You received this message because you are

Re: [algogeeks] facebook interview question

2011-11-28 Thread Aamir Khan
Take numbers in pair of 2, compare with each other and then compare the maximum among them with max (maximum element so far) and minimum among them with min (minimum element so far) , In this way you will be able to find max, min in 3 comparisons for each 2 integers. Hence 3n/2 comparisons needed

[algogeeks] Re: Number Theory (Power of 3 )

2011-11-28 Thread Dave
@SAMM: Something like this might work: bool PowerOfThree(unsigned int n) { int powsof2[5] = {16,8,4,2,1}; int powsof3[32] = {1,3,0,9,27,0,81,243,0,729,0,2187,6561,0,19683,59049,0,177147,0,531441,1594323,0, 4782969,14348907,0,43046721,129140163,0,387420489,0,1162261467,3486784401};

[algogeeks] Sub-array problem

2011-11-28 Thread Mohit kumar lal
Given a array of positive integers ,You have to find the largest sum possible from consecutive sub-array but sum should be less than or equal to K and also find that sub-array. Ex- array={2,1,3,4,5} k=12, ans-12, sub-array={3,4,5} Firstly i tried with brute-force and then i also tried to solve

[algogeeks] Re: facebook interview question

2011-11-28 Thread Dave
@Atul: Your code uses 2*n - 2 comparisons. Thus, it is non-responsive to the problem of using something close to 3*n/2 comparisons. Dave On Nov 28, 12:20 pm, atul anand atul.87fri...@gmail.com wrote: void findMinMax(int arr[],int len,int *min,int *max) {   int tempMin,tempMax,i;  

Re: [algogeeks] Re: facebook interview question

2011-11-28 Thread atul anand
yup...wrong solution by me Aamir solution is correct. On Tue, Nov 29, 2011 at 3:17 AM, Dave dave_and_da...@juno.com wrote: @Atul: Your code uses 2*n - 2 comparisons. Thus, it is non-responsive to the problem of using something close to 3*n/2 comparisons. Dave On Nov 28, 12:20 pm, atul