Re: [algogeeks] Facebook question!

2012-10-01 Thread Rahul Singh
check this out..

#includeiostream
#includestdlib.h
using namespace std;

void print_sets(string *s,int pos,int n,char *to_print)
{
if(pos==n)
{
return;
}

for(int i=0;is[pos].length();i++)
{
to_print[pos] =  s[pos][i];
print_sets(s,pos+1,n,to_print);
if(pos==n-1)
{
for(int j=0;jn;j++)coutto_print[j];
coutendl;
}
}
return;
}
int main()
{
int n;
cinn;
string s[n];

for(int i=0;in;i++)
{
cins[i];
}
 char *to_print = new char[n];
print_sets(s,0,n,to_print);
}

-- 
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] Facebook question!

2012-10-01 Thread Rahul Singh
check this out..

#includeiostream
#includestdlib.h
using namespace std;

void print_sets(string *s,int pos,int n,char *to_print)
{
if(pos==n)
{
return;
}

for(int i=0;is[pos].length();i++)
{
to_print[pos] =  s[pos][i];
print_sets(s,pos+1,n,to_print);
if(pos==n-1)
{
for(int j=0;jn;j++)coutto_print[j];
coutendl;
}
}
return;
}
int main()
{
int n;
cinn;
string s[n];

for(int i=0;in;i++)
{
cins[i];
}
 char *to_print = new char[n];
print_sets(s,0,n,to_print);
}

-- 
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] finding element in array with minimum of comparing

2012-10-01 Thread Navin Kumar
@atul:
still it won't compare 0 th element. Slight modification in your code:

n=*sizeof(arr)*;
do
{
 if(elem==arr[*--n*])
 print found;

}while(n);

On Mon, Oct 1, 2012 at 9:50 AM, atul anand atul.87fri...@gmail.com wrote:

 yes, but there no need of checking outside the loop

 n=sizeof(arr)-1;
 do
 {
  if(elem==arr[n])
  print found;
 n--;

 }while(n);



 On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar algorithm.i...@gmail.comwrote:

 @atul: keep one more checking outside loop for element at 0 th index.
 Because when n = 0  the your loop come out from the loop without comparing
 it.


 On Mon, Oct 1, 2012 at 8:55 AM, atul anand atul.87fri...@gmail.comwrote:

 n=sizeof(arr);
 n--;

 while(n)
 {
  if(elem=arr[n])
   print found;

 n--;

 }

 On Sun, Sep 30, 2012 at 2:56 PM, רפי וינר rafiwie...@gmail.com wrote:

 Hi
 i was in an interview and was given a simple function
 int arrExsits(int* arr,int size,int elem){
 for (int i=0;isize;++i)
 if(elem==arr[i])
return i;
 return -1;
 }
 this function does 2n compares
 n- the if statment
 n-check that i is smaller then size
 i was suppose to give an optimal (less compares) solution so i gave

 int arrExsits(int* arr,int size,int elem){
 if (arr[size-1]==elem)
 return size-1;
 arr[size-1]=elem]
 for (int i=0;;++i)
 if(elem==arr[i]){
 if (i!=size-1)
 return i;
 return -1;
 }
 this solution works and it has n+2 compares the first one another n and
 the second inner if.
 they told me it's good (and I've passed) but they told just for my
 knowledge that there is a better N compare solution.
 I've searched the web but couldn't find it.
 anybody knows?
 Thanks

 --
 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.


  --
 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] finding element in array with minimum of comparing

2012-10-01 Thread vikas
still there is no improvement, compiler will generate the code to compare 
with zero here. what you have accomplished is , hide it from human eyes

On Monday, 1 October 2012 15:25:09 UTC+5:30, Navin Kumar wrote:

 @atul: 
 still it won't compare 0 th element. Slight modification in your code:

 n=*sizeof(arr)*;
 do
 {
  if(elem==arr[*--n*])
  print found;

 }while(n);

 On Mon, Oct 1, 2012 at 9:50 AM, atul anand atul.8...@gmail.comjavascript:
  wrote:

 yes, but there no need of checking outside the loop

 n=sizeof(arr)-1;
 do
 {
  if(elem==arr[n])
  print found;
 n--;

 }while(n);



 On Mon, Oct 1, 2012 at 9:33 AM, Navin Kumar 
 algorit...@gmail.comjavascript:
  wrote:

 @atul: keep one more checking outside loop for element at 0 th index. 
 Because when n = 0  the your loop come out from the loop without comparing 
 it.


 On Mon, Oct 1, 2012 at 8:55 AM, atul anand atul.8...@gmail.comjavascript:
  wrote:

 n=sizeof(arr);
 n--;

 while(n)
 {
  if(elem=arr[n])
   print found;

 n--;

 }

 On Sun, Sep 30, 2012 at 2:56 PM, רפי וינר rafiw...@gmail.comjavascript:
  wrote:

 Hi
 i was in an interview and was given a simple function
 int arrExsits(int* arr,int size,int elem){
 for (int i=0;isize;++i)
 if(elem==arr[i])
return i;
 return -1;
 }
 this function does 2n compares 
 n- the if statment
 n-check that i is smaller then size
 i was suppose to give an optimal (less compares) solution so i gave

 int arrExsits(int* arr,int size,int elem){
 if (arr[size-1]==elem)
 return size-1;
 arr[size-1]=elem]
 for (int i=0;;++i)
 if(elem==arr[i]){
 if (i!=size-1)
 return i;
 return -1;
 }
 this solution works and it has n+2 compares the first one another n 
 and the second inner if.
 they told me it's good (and I've passed) but they told just for my 
 knowledge that there is a better N compare solution.
 I've searched the web but couldn't find it.
 anybody knows?
 Thanks 

 -- 
 You received this message because you are subscribed to the Google 
 Groups Algorithm Geeks group.
 To post to this group, send email to algo...@googlegroups.comjavascript:
 .
 To unsubscribe from this group, send email to 
 algogeeks+...@googlegroups.com javascript:.
 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 algo...@googlegroups.comjavascript:
 .
 To unsubscribe from this group, send email to 
 algogeeks+...@googlegroups.com javascript:.
 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 algo...@googlegroups.comjavascript:
 .
 To unsubscribe from this group, send email to 
 algogeeks+...@googlegroups.com javascript:.
 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 algo...@googlegroups.comjavascript:
 .
 To unsubscribe from this group, send email to 
 algogeeks+...@googlegroups.com javascript:.
 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 view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/_r1SRmzZYjcJ.
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] Re: microsoft_c++_qstn

2012-10-01 Thread vikas
not sure what interviewer meant here, does not look like compiler dependent 
code, 
and BTW, last recurrence yield 5 :) and not 8,
one possible def is, you have a function with no return and compiler 
is independent for choosing what to return in this case, just a guess. Not 
sure about cpp standard


On Tuesday, 25 September 2012 21:27:49 UTC+5:30, Ravi Ranjan wrote:

 #includeiostream.h
 int rec(int i)
 {
 static int d=1;
 if(i=5)
 return i;
 d=d+i;
 i=i+i;
 rec(d);
 }
 int main()
 {
 coutrec(1);
 return 0;
 }

 various compilers give diffrent result... why so???
 n how d value is calculated by differnt compilers.. whhat is d correct 
 output n which compiler to trust??
  

-- 
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/-/hV_vZm8wQH0J.
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 : all anagrams next to each other

2012-10-01 Thread shashi kant
A solution given below taken from cracking the Coding interview  book...

Solution is create a Comparator and a small change in compare method is
that u sort the characters of that string and then compare.

and just sort the arrays, using this compareTo method instead of the usual
one.
Arrays.sort(array, new AnagramComparator());



public class AnagramComparator implements ComparatorString {
public String sortChars(String s) {
char[] content = s.toCharArray();
Arrays.sort(content);
return new String(content);
}
public int compare(String s1, String s2) {
return sortChars(s1).compareTo(sortChars(s2));
}
}






*Shashi Kant *
***Think positive and find fuel in failure*
http://thinkndoawesome.blogspot.com/
*System/Software Engineer*
*Hewlett-Packard India Software Operations.
*



On Sun, May 27, 2012 at 2:56 AM, Navin Gupta navin.nit...@gmail.com wrote:

 @jalaj :-  we will be sorting a copy of the word and then matching the
 sorted_sequence with the sorted_sequence of the copy of other words.
 It will still be in-place, because we are using a space of Word size where
 the input is a dictionary.
 This is an amortized in-place.

 --
 Navin Kumar Gupta
 Computer Science  Engg.
 National Institute of Technology,Jamshedpur

  --
 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/-/n2tGzVxSLIYJ.

 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] Facebook question!

2012-10-01 Thread saurabh agrawal
Do we need to handle cases when the same string will appear again??
In that case we can sort individual array and remove duplicates.

On Mon, Oct 1, 2012 at 9:54 AM, Rahul Singh riit1...@gmail.com wrote:

 check this out..

 #includeiostream
 #includestdlib.h
 using namespace std;

 void print_sets(string *s,int pos,int n,char *to_print)
 {
 if(pos==n)
 {
 return;
 }

 for(int i=0;is[pos].length();i++)
 {
 to_print[pos] =  s[pos][i];
 print_sets(s,pos+1,n,to_print);
 if(pos==n-1)
 {
 for(int j=0;jn;j++)coutto_print[j];
 coutendl;
 }
 }
 return;
 }
 int main()
 {
 int n;
 cinn;
 string s[n];

 for(int i=0;in;i++)
 {
 cins[i];
  }
  char *to_print = new char[n];
 print_sets(s,0,n,to_print);
 }

  --
 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] Given a two dimensional graph with points on it, find a line which passes the most number of points.

2012-10-01 Thread shashi kant
Given a two dimensional graph with points on it, find a line which passes
the most number of points.
Can somebody suggest possible ways to do it.

*(or point me to the post if this problem is already discussed)*



*Thanks  Regards,*
*Shashi Kant *
***Think positive and find fuel in failure*
http://thinkndoawesome.blogspot.com/
*System/Software Engineer*
*Hewlett-Packard India Software Operations.
*

-- 
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] Re: Given a two dimensional graph with points on it, find a line which passes the most number of points.

2012-10-01 Thread Dave
@Shashi: It has been discussed before, and an O(n^2 log n) solution is 
outlined at 
https://groups.google.com/d/msg/algogeeks/fBhXY9aUNJ0/CTB_p7uO8YYJ and is 
given in more detail at 
https://groups.google.com/d/msg/algogeeks/fBhXY9aUNJ0/0S0zK6HdKdMJ.
 
Dave

On Monday, October 1, 2012 12:00:19 PM UTC-5, Shashi Kant wrote:

 Given a two dimensional graph with points on it, find a line which passes 
 the most number of points. 
 Can somebody suggest possible ways to do it.

 *(or point me to the post if this problem is already discussed)*



 *Thanks  Regards,*
 *Shashi Kant *
 ***Think positive and find fuel in failure*
 http://thinkndoawesome.blogspot.com/
 *System/Software Engineer*
 *Hewlett-Packard India Software Operations.
 *




-- 
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/-/TW09gurbAN0J.
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: Given a two dimensional graph with points on it, find a line which passes the most number of points.

2012-10-01 Thread shashi kant
thanks @dave


*Shashi Kant *
***Think positive and find fuel in failure*

*System/Software Engineer*
*Hewlett-Packard India Software Operations.
*



On Mon, Oct 1, 2012 at 10:42 PM, Dave dave_and_da...@juno.com wrote:

 @Shashi: It has been discussed before, and an O(n^2 log n) solution is
 outlined at
 https://groups.google.com/d/msg/algogeeks/fBhXY9aUNJ0/CTB_p7uO8YYJ and is
 given in more detail at
 https://groups.google.com/d/msg/algogeeks/fBhXY9aUNJ0/0S0zK6HdKdMJ.

 Dave

 On Monday, October 1, 2012 12:00:19 PM UTC-5, Shashi Kant wrote:

 Given a two dimensional graph with points on it, find a line which passes
 the most number of points.
 Can somebody suggest possible ways to do it.

 *(or point me to the post if this problem is already discussed)*



 *Thanks  Regards,*
 *Shashi Kant *
 ***Think positive and find fuel in failure*
 http://thinkndoawesome.**blogspot.com/http://thinkndoawesome.blogspot.com/
 *System/Software Engineer*
  *Hewlett-Packard India Software Operations.
 *


  --
 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/-/TW09gurbAN0J.
 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] Design an OO representation to model HTML.

2012-10-01 Thread ~*~VICKY~*~
Could someone throw some light on this OOPS question. I detailed
explanation would be of immense help.

Design an OO representation to model HTML.
How do they represent tags and content? What about containment
relationships? Bonus points if they know that this has already been done a
bunch of times, e.g. with DOM. But they still have to describe it.


-- 
Cheers,

  Vicky

-- 
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] Print Permutaion of a given String

2012-10-01 Thread rahul sharma


-- 
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.