Re: [algogeeks] Re: Array , Number Missing or Duplicate ..

2011-03-01 Thread Abhijit K Rao
I can think of 2 methods if Hashing is not allowed.

1.  Plain comparison of every element with an other element, which takes
O(n2)

2.  We can sort the array, and the best we could achieve is O(nlogn) after
that use simple comparision,
like the code here : http://codepad.org/RtRbnyAN; Overall we can
optimize it best to O(n)

Best Regards
Abhijit


On Sun, Feb 27, 2011 at 7:15 PM, Dave  wrote:

> If hashing is disallowed, then I think the best method is to sort the
> data and check for consecutive triplicates. O(n log n).
>
> Dave
>
> On Feb 27, 6:35 am, bittu  wrote:
> > @Gaurav Hey I forgot to say Hashing is not allowed sum thing other
> > then this better solution
> >
> > @radha i don't think ur method works here chk out ur methodhttp://
> codepad.org/oTDNSoeu
> >
> > Thanks
> > Shashank
>
> --
> 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] [brain teaser ] 25february

2011-02-26 Thread Abhijit K Rao
The age guy of bus driver is the age of the puzzle solver.

Best Regards
Abhijit


On Sat, Feb 26, 2011 at 1:05 PM, Lavesh Rawat wrote:

> *Bus Driver Problem Solution*
>
> ok let's say you're driving a bus and it's empty. At the first stop two(2)
> people get on. At the second stop five(5) people get on and one(1) person
> exits. At the third stop six(6) people get on and four(4) people exit. How
> old is the bus driver?
>
> Update Your Answers at : Click 
> Here
>
> Solution:
> Will be updated after 1 day
>
> --
>
> "Never explain yourself. Your friends don’t need it and
> your enemies won’t believe 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
> 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] interview quest..

2011-02-06 Thread Abhijit K Rao
I could not get it for recursively, but iteratively, I coded a solution. If
anyone knows recursively,
let us know please.

#include
void main()
{
 char s[18]="DGGDBCBHH";
 int i=0,j=0;
 int count;
 while(s[i]!='\0')
 {
  if(s[i] == s[i+1])
  {
  count = strlen(s)-2;
  while(count--)
  {
   s[i]=s[i + 2];
   i++;
  }
  s[i]='\0';
  i=0;
  }
 else
 {
 i++;
 }
 }
 printf("%s",s);
 getch();
}


I/P:  DGGDBCBHH  O/P: BCB

Best Regards
Abhijit


On Sun, Feb 6, 2011 at 1:47 PM, ramkumar santhanam
wrote:

> use stack.
>
>  --
> 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] Microsoft

2011-02-06 Thread Abhijit K Rao
How about , using a sorting algorithm like Quick sort and return diff of
last and the before last element.

Best Regards
Abhijit


On Sun, Feb 6, 2011 at 3:29 PM, Decipher  wrote:

>
> Algorithm to find the two numbers whose difference is minimum among the set
> of numbers.
>
> For example the sequence is 5, 13, 7, 0, 10, 20, 1, 15, 4, 19
>
> The algorithm should return min diff = 20-19 = 1.
>
> Constraint - Time Complexity O(N) & Space is not a constraint [upto O(3N)]
>
>
>  --
> 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] algo to count the items in a list

2010-10-18 Thread Abhijit K Rao
The most crude method would be to do a comparison in the entire array list
and increment as and when we find a match.
But this method gives a complexity of O(n2).

The same method above can be used , and comparisons can be done from either
ends of array, which reduces the
complexity to O(n2 / 2)

The last , is we could create a BST with the input, Basically insert the
names in BST, and when we inset we do a comparision
if its already inserted , just increment the count of each name, the
complexity of this method can be O(log n)

Best Regards
Abhijit


On Fri, Oct 15, 2010 at 7:00 AM, Kumar S  wrote:

> Q : A file has list of names. We need an algorithm to find the number each
> names repeats in that list. NOT case sensitive
>
> Example...
>
> namefile.txt has the content..
>
> bob
> abi
> jack
> ram
> jim
> tim
> joey
> riya
> kris
> bob
> kris
> ram
> jack
> joe
> joe
> joey
> bob
> bob
> bob
> kris
> joe
>
>
> this has more than 32000 in the list..  not limited number .
>
> Output : must have the distinct names and the count against them..
>
> Appreciate your inputs.
>
> Thanks n have a good one
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@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 algoge...@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.