Re: [algogeeks] Re: Microsoft interview question

2012-05-19 Thread anuj agarwal
U are checking if the sum is same or not.. which can be same even if the
elements are different.

On Sun, May 20, 2012 at 11:54 AM, Piyush Khandelwal <
piyushkhandelwal...@gmail.com> wrote:

> Hiii!! I have some idea about the solution. Please notify me if i am
> wrong
>
> a= [ 4,3,5 ] and b= [ 3,5,4 ]
> diff=0;
> for (i=0; i { diff= diff+a[i]-b[i];
> }
> if diff == 0
>  print: permutation
> else
>  print: not permutation
>
>
>
>
>
> On 20 May 2012 07:2 0, Dave  wrote:
>
>> @Harshit: These are a few unanswered questions that came to mind when I
>> read your solution attempt: What do you do with negative elements? What is
>> the -12th prime number? How do you deal with overflow in the cases where
>> you have a lot of large prime numbers and the product exceeds your native
>> data types?
>>
>> Dave
>>
>> On Saturday, May 19, 2012 2:29:52 PM UTC-5, harshit pahuja wrote:
>>
>>> given 2 unsorted integer arrays a and b of equal size. Determine if b is
>>> a permutation of a. Can this be done in O(n) time and O(1) space ?
>>>
>>>
>>>
>>>
>>> please help me with my solution
>>>
>>>
>>> suppose a --  3 5 4
>>>  b --  4 3 5
>>>
>>> now we replace a[i] with a[i]..th prime number  and b with b[i] .. th
>>> prime number
>>>
>>>   now array  a becomes  5 11 7
>>>  array  b becomes  7 5 11
>>>
>>> now we take product of elements of array a and do the same with array  b
>>> elements
>>> if product is equal  then b is a permutation of a
>>>
>>  --
>> 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/-/WEW0M5VUUVEJ.
>>
>> 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.
>>
>
>
>
> --
> *Piyush Khandelwal***
> Mobile No: 91-8447229204
>  91-9808479765
>
>
>  --
> 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] c output

2011-06-01 Thread anuj agarwal
This will be same as:
b=b+1;
b=b+1;
a=b*b;

Basically, all prefix increment and decrement operators will be executed
first. Similarly all postfix operators will be executed at last.

Anuj Agarwal
Engineering is the art of making what you want from things you can get.


On Wed, Jun 1, 2011 at 5:27 PM, Vishal Thanki wrote:

> you may want to read: http://c-faq.com/expr/seqpoints.html
>
> On Wed, Jun 1, 2011 at 5:19 PM, himanshu kansal
>  wrote:
> > a=++b*++b;
> > if b=3 initially, then a is coming out to be 25.why
> >
> > --
> > 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.



[algogeeks] Admin of Group

2011-05-25 Thread anuj agarwal
Hi,

Are there any admins on this group? I recently joined this group and i liked
the discussions going on here.

But there is a problem which hurts is that unlike other groups which are
moderated by certain admin guys (also active members of group), this one is
not.
So we are receiving lots of SPAMS. I guess no body wants to get a job from
this group (specially ones which are sent by some Panzer).

If the mods are reading this, Please take some action on that mails so that
group will remain clean.

Sorry for off topic.

Anuj Agarwal
Engineering is the art of making what you want from things you can get.

-- 
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] Re: Facebook Interview Question from glassdoor

2011-05-23 Thread anuj agarwal
Immanuel,
We can keep c and n arrays as global variable as they are not part of state
of the recursion.

Anuj Agarwal
Engineering is the art of making what you want from things you can get.


On Mon, May 23, 2011 at 10:04 PM, immanuel kingston <
kingston.imman...@gmail.com> wrote:

> small correction
>
> On Mon, May 23, 2011 at 9:46 PM, immanuel kingston <
> kingston.imman...@gmail.com> wrote:
>
>> A Recursive soln:
>>
>>
>> NUM_PER_DIGIT = 3
>> char c[][NUM_PER_DIGIT] = {"abc","def",...};
>>
>> char n[] = 2156169 (number is pressed);
>> int k=7;
>> char * s = (char *) malloc(sizeof(char) * k);
>>
>> void printAllCombinations (char c[][], char n[], int k, char *s, int
>> count) {
>> if (count >= k - 1) {
>> s[k] = '\0';
>> print (s);
>> } else {
>> for (i =0; i< NUM_PER_DIGIT; i++) {
>>  *s[i] = c[n[count]][i];*
>>
>> printAllCombinations(c,n,k,s, count+1);
>> }
>> }
>> }
>> printAllCombinations (c,n,k,s,0);
>>
>> Please correct me if my understanding is wrong.
>>
>> Thanks,
>> Immanuel
>>
>>
>> On Mon, May 23, 2011 at 9:33 PM, immanuel kingston <
>> kingston.imman...@gmail.com> wrote:
>>
>>> Extending the above soln:
>>>
>>> NUM_PER_DIGIT = 3
>>> char c[][NUM_PER_DIGIT] = {"abc","def",...};
>>>
>>> char n[] = 2156169 (number is pressed);
>>> int k=7;
>>>
>>> for i <-- 0 to  NUM_PER_DIGIT ^ k
>>> String s="";
>>> for j <-- 0 to k
>>> int index =
>>> getJthDigitinItotheBaseNumPerDigit(NUM_PER_DIGIT,i,j); // ie get 1st digit
>>> in (022)3 returns 2
>>> s += c[n[j]][index];
>>> print(s);
>>>
>>>
>>> Time Complexity: O((NUM_PER_DIGIT^k)*k^2);
>>>
>>>
>>> On Mon, May 23, 2011 at 7:32 PM, anshu mishra >> > wrote:
>>>
>>>> the same question i have asked in microsoft interview. (if it is the
>>>> same :P)
>>>>
>>>> for 12 perutation are (ad, ae, af, bd, be, bf, cd, ce ,cf);
>>>> i have given them 3 solution(recusrsive, stack based) and the last one
>>>> what they wanted.
>>>>
>>>> take a tertiary number(n) = 3^(number of digits) in case of 12 it is
>>>> equals to 2;
>>>>
>>>> i m solving the save problem. assuming on every key there are only 2
>>>> alphabets.
>>>>
>>>> char c[][2] = {ab , cd, ..};
>>>>
>>>> char n[] = 2156169 (number is pressed);
>>>> so k = 7;
>>>> for (i = 0; i < (1<>>> string s = "";
>>>>  for (j = 0; j < k; j++){
>>>>  s += c[n[j]][i & (1<>>> }
>>>> print(s);
>>>> }
>>>>
>>>> same logic u can use for tertiary too.
>>>>
>>>>  --
>>>> 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] Re: sum of two

2011-05-20 Thread anuj agarwal
@Dave: He is talking of a better hash function. You did not mention the hash
function which you will use.

Anuj Agarwal

Engineering is the art of making what you want from things you can get.


On Sat, May 21, 2011 at 9:59 AM, Dave  wrote:

> @Apoorve: See my response at
> http://groups.google.com/group/algogeeks/msg/72419fb69ce97774.
>
> Dave
>
> On May 20, 10:05 am, Apoorve Mohan  wrote:
> > @dave: i think this can be handled using a good hash function(an onto
> > function). then the space complexity will also be O(n). What say???
> >
> >
> >
> >
> >
> > On Fri, May 20, 2011 at 8:31 PM, Dave  wrote:
> > > @Aakash: And tell me how map works. Is making an entry O(1) regardless
> > > of the value of the entry? For example, is it O(n) to map the sequence
> > > 1, 4, 9, 16, 25, ..., n^2?
> >
> > > Dave
> >
> > > On May 20, 9:39 am, Aakash Johari  wrote:
> > > > @Dave: I got you. I will have to check before pushing the element in
> map.
> >
> > > > On Fri, May 20, 2011 at 7:30 AM, Dave 
> wrote:
> > > > > @Aakash: Yeah, but try the same array with sum = 6 and see what
> > > > > happens.
> >
> > > > > Dave
> >
> > > > > On May 20, 9:04 am, Aakash Johari  wrote:
> > > > > > int main()
> > > > > > {
> > > > > > int a[10] = {5, 3, 10, 9, 8, 23, 11, 4, 12, 6};
> > > > > > int i;
> > > > > > int sum;
> > > > > > int flag = 0;
> >
> > > > > > map m;
> >
> > > > > > for ( i = 0; i < 10; i++ ) {
> > > > > > m[a[i]] = 1;
> > > > > > }
> >
> > > > > > sum = 13;
> >
> > > > > > for ( i = 0; i < 10; i++ ) {
> > > > > > if ( m[sum - a[i]] == 1 ) {
> > > > > > flag = 1;
> > > > > > break;
> > > > > > }
> > > > > > }
> >
> > > > > > if ( flag == 1 )
> > > > > > cout << a[i] << " " << sum - a[i] << endl;
> >
> > > > > > return 0;
> >
> > > > > > }
> > > > > > On Fri, May 20, 2011 at 7:01 AM, hari 
> wrote:
> > > > > > > We can sort using STL sort function in main() before function
> call
> > > of
> > > > > > > arraysum().
> >
> > > > > > > On May 20, 6:49 am, Gunjan Sharma 
> > > wrote:
> > > > > > > > First of all there is an infinite loop in this code
> > > > > > > > Secondly it works only for sorted array.
> >
> > > > > > > > On Fri, May 20, 2011 at 7:16 PM, hari 
> > > wrote:
> > > > > > > > > In while loop have i,j which points first and last index of
> > > array.
> > > > > In
> > > > > > > > > while loop, Check the sum of a[i],a[j], If sum i or
> > > > > else
> > > > > > > > > decrement j. Run the while loop till i >
> > > > > > > > > CODE:
> >
> > > > > > > > > int arraysum(int a[], int k, int i, int j)
> > > > > > > > > while(i > > > > > > > > {
> > > > > > > > >  int p=0;
> > > > > > > > >  int b[10]; //to store index of selected nos
> > > > > > > > >  sum=a[i]+a[j];
> > > > > > > > >  if (sum==k)
> > > > > > > > >  {
> > > > > > > > >  b[p++]=i;b[p++]=j;
> > > > > > > > >  }
> > > > > > > > >  elseif(sum > > > > > > > >  i++;
> > > > > > > > >  else(sum>k)
> > > > > > > > >  j++;
> > > > > > > > >  return b;
> > > > > > > > > }
> >
> > > > > > > > > On May 20, 4:38 am, amit  wrote:
> > > > > > > > > > given an array of integers, and an integer k, find out
> two
> > > > > elements
> > > > > > > > > > from the array whose sum is k in O(n) time. if

Re: [algogeeks] Re: PUZZLE

2011-05-20 Thread anuj agarwal
@Dave: The problem statement says, the elephant can take 1000 at a time.
If he take max 1000, and eat 1 banana in each 1 km travel, he will be having
0 after 1000 Km.

Anuj Agarwal

Engineering is the art of making what you want from things you can get.


On Sat, May 21, 2011 at 9:57 AM, Dave  wrote:

> @Wladimir: According to the problem statement, the elephant starts out
> with 3,000 bananas. I am saying that the elephant can deliver 534
> bananas to the destination 1,000 km away.
>
> Dave
>
> On May 20, 7:22 pm, Wladimir Tavares  wrote:
> > with 534 , the elephant can travel only 534 Km! I am right?
> > Wladimir Araujo Tavares
> > *Federal University of CearĂ¡
> >
> > *
> >
> >
> >
> > On Fri, May 20, 2011 at 8:36 PM, Dave  wrote:
> > > Upon reading the problem more carefully, the answer is 534 bananas,
> > > not 533-1/3.
> >
> > > Dave
> >
> > > On May 20, 3:43 pm, Dave  wrote:
> > > > @Bhavesh: 533-1/3.
> >
> > > > Dave
> >
> > > > On May 20, 10:47 am, Bhavesh agrawal  wrote:
> >
> > > > > 1 elephant can take 1000 banana at a time and eat 1 banana after
> each
> > > 1km
> > > > > travel.
> > > > > total bananas are 3000 and distance have to travel from A to B is
> > > 1000km.
> >
> > > > > So how many max bananas he can take from A to B.   (he'll eat in
> return
> > > > > travel  too)- Hide quoted text -
> >
> > > > - Show quoted text -
> >
> > > --
> > > 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.- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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] Re: GOOGLE Q

2011-05-17 Thread anuj agarwal
Same method as Gene told.
Only enhancement u can made is start from the word nearer to sorted string
and compare till the nearest word of the reverse of sorted string.
You don't need to check the whole dictionary.

Anuj Agarwal

Engineering is the art of making what you want from things you can get.


On Wed, May 18, 2011 at 6:01 AM, Gene  wrote:

> Sort the characters in the string. Go through the dictionary sorting the
> characters in each word in turn.  Print the words whose sorted versions
> match the sorted string.
>
> You can quickly print all equivalence classes of anagrams in the dictionary
> by hashing with the sorted strings as keys. It only takes a few seconds to
> get them all this way with a 2-line perl or ruby script.
>
> --
> 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] Print Subsets

2011-05-16 Thread anuj agarwal
Correct. Its a variant of Knapsack problem.

Anuj Agarwal

Engineering is the art of making what you want from things you can get.


On Mon, May 16, 2011 at 4:53 PM, anshu mishra wrote:

> its DP problem can be solved in O(m*n)
> where m is number of elements in array and n is value of the given number.
>
> --
>  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] Array problem

2011-05-16 Thread anuj agarwal
Kunal,
Your solution runs in O(n) time but it is a wrong solution. It will run fine
if the array is sorted.

Anuj Agarwal

Engineering is the art of making what you want from things you can get.


On Mon, May 16, 2011 at 7:17 PM, Kunal Patil  wrote:

> @Piyush Sinha: I doubt correctness of your solution. And even if it gets
> out to be correct It is not O(n)
> My approach:
> Maintain 2 variables: curr_max and prev_max to keep knowledge about current
> maximum length and previous maximum length.
>
> Algorithm:
>
> *initialize curr_max and prev_max to 1
>
> for i=0 to size-2
>if next element of array is greater than current element
>  {
>   increment curr_max;
>   check whether curr_max is greater than prev_max, if yes,
> assign   curr_max to prev_max;
>  }
>else // next element is smaller than or equal to current element
>  reset curr_max to 1;
> //End for
>
> Finally return prev_max*
>
> This is clearly O(n) as it iterates through array only once.
>
> --
>  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] Array problem

2011-05-15 Thread anuj agarwal
How about create a BST and then, for each node find the difference between
the node and its child and do this for all except leaf nodes.
If u want i will write the code for the same.

Anuj Agarwal

Engineering is the art of making what you want from things you can get.


On Mon, May 16, 2011 at 11:20 AM, anshu mishra wrote:

> @amit ur code is wrong. just check it for this {5, 4, 1, 8, 4, 4};
>
> --the
> 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.