Re: [algogeeks] Google Interview Question: In how many intervals does a number exists

2013-06-09 Thread Prateek Jain
2-2 as 2 lies in [2,3] and [1,4] ?


On Sun, Jun 9, 2013 at 12:50 PM, Monish Gupta monish.gup...@gmail.comwrote:

 There are n Intervals. Given a set of m numbers, tell in how many
 intervals does each number exists.
 Example: 4 Intervals: [2,3] [3,4] [1,4] [3,10]. Numbers {2,4,11}
 For 2 - 1 as 2 lies only in 1 interval [2,3]
 For 4 - 3 as 4 lies in 3 intervals
 For 11 - 0 as 11 lies in none of the given 4 intervals.

 It can be easily done in O(m*n) by traversing n intervals for each number
 in the given set of m numbers. How would improve this?

 Note: I could not fully recall, but I have seen very similar question in
 codechef but could not find the same.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.




-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Google Interview Question: In how many intervals does a number exists

2013-06-09 Thread Avi Dullu
Read up on Interval trees http://en.wikipedia.org/wiki/Interval_tree.

Programmers should realize their critical importance and responsibility in
a world gone digital. They are in many ways similar to the priests and
monks of Europe's Dark Ages; they are the only ones with the training and
insight to read and interpret the scripture of this age.


On Sun, Jun 9, 2013 at 12:20 AM, Monish Gupta monish.gup...@gmail.comwrote:

 There are n Intervals. Given a set of m numbers, tell in how many
 intervals does each number exists.
 Example: 4 Intervals: [2,3] [3,4] [1,4] [3,10]. Numbers {2,4,11}
 For 2 - 1 as 2 lies only in 1 interval [2,3]
 For 4 - 3 as 4 lies in 3 intervals
 For 11 - 0 as 11 lies in none of the given 4 intervals.

 It can be easily done in O(m*n) by traversing n intervals for each number
 in the given set of m numbers. How would improve this?

 Note: I could not fully recall, but I have seen very similar question in
 codechef but could not find the same.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to algogeeks+unsubscr...@googlegroups.com.




-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.




Re: [algogeeks] Google Interview Question

2011-10-01 Thread arvind kumar
Hi
Are u attending off-campus or on-campus interview?

On 10/1/11, R@TH!$H rathishkan...@gmail.com wrote:
 Hi,

 I am attending Google interview on Monday. Please help me with sample
 questions.

 Thanks  Regards,
 Rathish Kannan

 --
 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] Google Interview Question

2011-10-01 Thread Rathish Kannan
off campus.

--  RK :)


On Sat, Oct 1, 2011 at 11:59 AM, arvind kumar arvindk...@gmail.com wrote:

 Hi
 Are u attending off-campus or on-campus interview?

 On 10/1/11, R@TH!$H rathishkan...@gmail.com wrote:
  Hi,
 
  I am attending Google interview on Monday. Please help me with sample
  questions.
 
  Thanks  Regards,
  Rathish Kannan
 
  --
  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] Google Interview Question

2011-10-01 Thread Deepak Garg
hey,,,what is the process of attending google offcampus process.

kindly let us know..

On Sat, Oct 1, 2011 at 1:52 PM, Rathish Kannan rathishkan...@gmail.comwrote:

 off campus.

 --  RK :)



 On Sat, Oct 1, 2011 at 11:59 AM, arvind kumar arvindk...@gmail.comwrote:

 Hi
 Are u attending off-campus or on-campus interview?

 On 10/1/11, R@TH!$H rathishkan...@gmail.com wrote:
  Hi,
 
  I am attending Google interview on Monday. Please help me with sample
  questions.
 
  Thanks  Regards,
  Rathish Kannan
 
  --
  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.




-- 
U.D.I.T

Sent by Nokia OVI (c)

-- 
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] Google Interview Question

2011-10-01 Thread Rathish Kannan
apply through google careers site...

--  RK :)


On Sat, Oct 1, 2011 at 2:02 PM, Deepak Garg deepakgarg...@gmail.com wrote:

 hey,,,what is the process of attending google offcampus process.

 kindly let us know..


 On Sat, Oct 1, 2011 at 1:52 PM, Rathish Kannan rathishkan...@gmail.comwrote:

 off campus.

 --  RK :)



 On Sat, Oct 1, 2011 at 11:59 AM, arvind kumar arvindk...@gmail.comwrote:

 Hi
 Are u attending off-campus or on-campus interview?

 On 10/1/11, R@TH!$H rathishkan...@gmail.com wrote:
  Hi,
 
  I am attending Google interview on Monday. Please help me with sample
  questions.
 
  Thanks  Regards,
  Rathish Kannan
 
  --
  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.




 --
 U.D.I.T

 Sent by Nokia OVI (c)

 --
 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] Google Interview Question

2011-10-01 Thread Deepak Garg
hey can pls share the link.

thnks

On Sat, Oct 1, 2011 at 2:04 PM, Rathish Kannan rathishkan...@gmail.comwrote:

 apply through google careers site...

 --  RK :)



 On Sat, Oct 1, 2011 at 2:02 PM, Deepak Garg deepakgarg...@gmail.comwrote:

 hey,,,what is the process of attending google offcampus process.

 kindly let us know..


 On Sat, Oct 1, 2011 at 1:52 PM, Rathish Kannan 
 rathishkan...@gmail.comwrote:

 off campus.

 --  RK :)



 On Sat, Oct 1, 2011 at 11:59 AM, arvind kumar arvindk...@gmail.comwrote:

 Hi
 Are u attending off-campus or on-campus interview?

 On 10/1/11, R@TH!$H rathishkan...@gmail.com wrote:
  Hi,
 
  I am attending Google interview on Monday. Please help me with sample
  questions.
 
  Thanks  Regards,
  Rathish Kannan
 
  --
  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.




 --
 U.D.I.T

 Sent by Nokia OVI (c)

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




-- 
U.D.I.T

Sent by Nokia OVI (c)

-- 
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] Google Interview Question

2011-10-01 Thread Anup Ghatage
FFS. here you go: http://lmgtfy.com/?q=google+careers

On Sat, Oct 1, 2011 at 2:09 PM, Deepak Garg deepakgarg...@gmail.com wrote:

 hey can pls share the link.

 thnks


 On Sat, Oct 1, 2011 at 2:04 PM, Rathish Kannan rathishkan...@gmail.comwrote:

 apply through google careers site...

 --  RK :)



 On Sat, Oct 1, 2011 at 2:02 PM, Deepak Garg deepakgarg...@gmail.comwrote:

 hey,,,what is the process of attending google offcampus process.

 kindly let us know..


 On Sat, Oct 1, 2011 at 1:52 PM, Rathish Kannan 
 rathishkan...@gmail.comwrote:

 off campus.

 --  RK :)



 On Sat, Oct 1, 2011 at 11:59 AM, arvind kumar arvindk...@gmail.comwrote:

 Hi
 Are u attending off-campus or on-campus interview?

 On 10/1/11, R@TH!$H rathishkan...@gmail.com wrote:
  Hi,
 
  I am attending Google interview on Monday. Please help me with sample
  questions.
 
  Thanks  Regards,
  Rathish Kannan
 
  --
  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.




 --
 U.D.I.T

 Sent by Nokia OVI (c)

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




 --
 U.D.I.T

 Sent by Nokia OVI (c)

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




-- 
Anup Ghatage

-- 
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] Google Interview Question

2011-10-01 Thread Siddhartha Banerjee
lol!!!

-- 
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] Google Interview Question

2011-08-01 Thread shady
when was this question asked in Google ? approximate date ? position ?

On Mon, Aug 1, 2011 at 1:45 PM, Abhishek Gupta gupta.abh...@gmail.comwrote:

 A is an array of size 2n such that first n elements are integers in any
 order and last n elements are characters.
 i.e. A={i1 i2 i3 in c1 c2 c3... cn}
 then we have to rearrange the elements such that final array is
 A ={ i1 c1 i2 c2 .. in cn}


 Example :
 input : A ={ 5,1,4,d,r,a};
 output : A= {5,d,1,r,4,a};

 --
 Abhishek Gupta
 MCA
 NIT Calicut
 Kerela

  --
 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] Google Interview Question

2011-08-01 Thread kumar raja
It is a bit tricky without using external memory
correct me if i am wrong.

for(i=n;i2*n;i++)
{


On 1 August 2011 02:42, shady sinv...@gmail.com wrote:

 when was this question asked in Google ? approximate date ? position ?


 On Mon, Aug 1, 2011 at 1:45 PM, Abhishek Gupta gupta.abh...@gmail.comwrote:

 A is an array of size 2n such that first n elements are integers in any
 order and last n elements are characters.
 i.e. A={i1 i2 i3 in c1 c2 c3... cn}
 then we have to rearrange the elements such that final array is
 A ={ i1 c1 i2 c2 .. in cn}


 Example :
 input : A ={ 5,1,4,d,r,a};
 output : A= {5,d,1,r,4,a};

 --
 Abhishek Gupta
 MCA
 NIT Calicut
 Kerela

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




-- 
Regards
Kumar Raja
M.Tech(SIT)
IIT Kharagpur,
10it60...@iitkgp.ac.in
7797137043.
09491690115.

-- 
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] Google Interview Question

2011-08-01 Thread kumar raja
It is a bit tricky without using external memory .It is like insertion sort.
correct me if i am wrong.

for(i=n;i2*n;i++)
{
   x=a[i];
for(j=i-1;;j--)
 {
if(j==0 || a[j-1]=='c')  // 'c' indicates some  character you can
check its ascii value
break;
a[j+1]=a[j];
  }

 a[j+1]=x;
}




On 1 August 2011 10:02, kumar raja rajkumar.cs...@gmail.com wrote:

 It is a bit tricky without using external memory
 correct me if i am wrong.

 for(i=n;i2*n;i++)
 {



 On 1 August 2011 02:42, shady sinv...@gmail.com wrote:

 when was this question asked in Google ? approximate date ? position ?


 On Mon, Aug 1, 2011 at 1:45 PM, Abhishek Gupta gupta.abh...@gmail.comwrote:

 A is an array of size 2n such that first n elements are integers in any
 order and last n elements are characters.
 i.e. A={i1 i2 i3 in c1 c2 c3... cn}
 then we have to rearrange the elements such that final array is
 A ={ i1 c1 i2 c2 .. in cn}


 Example :
 input : A ={ 5,1,4,d,r,a};
 output : A= {5,d,1,r,4,a};

 --
 Abhishek Gupta
 MCA
 NIT Calicut
 Kerela

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




 --
 Regards
 Kumar Raja
 M.Tech(SIT)
 IIT Kharagpur,
 10it60...@iitkgp.ac.in
 7797137043.
 09491690115.




-- 
Regards
Kumar Raja
M.Tech(SIT)
IIT Kharagpur,
10it60...@iitkgp.ac.in
7797137043.
09491690115.

-- 
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] Google Interview Question

2011-08-01 Thread Rohit jalan
Here is the recursive algo:

Rearrange(A,p,q)
1. if p is not equal to q do the following
2. r ← (p+q)/2
3. Exchange A[(p+r)/2..r] ←→ A[(p+q)/2 +1 ..(r+q)/2].
4. Rearrange(A,p,r)
5. Rearrange(A,r+1,q)
6. return



On Mon, Aug 1, 2011 at 1:45 PM, Abhishek Gupta gupta.abh...@gmail.comwrote:

 A is an array of size 2n such that first n elements are integers in any
 order and last n elements are characters.
 i.e. A={i1 i2 i3 in c1 c2 c3... cn}
 then we have to rearrange the elements such that final array is
 A ={ i1 c1 i2 c2 .. in cn}


 Example :
 input : A ={ 5,1,4,d,r,a};
 output : A= {5,d,1,r,4,a};

 --
 Abhishek Gupta
 MCA
 NIT Calicut
 Kerela

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




-- 
Regards :
ROHIT JALAN
B.E. Graduate,
Computer Science Department,
RVCE, Bangalore

-- 
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] Google Interview Question

2011-08-01 Thread Manmeet Singh
Your code does not works proper;y for all cases

On Mon, Aug 1, 2011 at 10:42 PM, Rohit jalan jalanha...@gmail.com wrote:

 Here is the recursive algo:

 Rearrange(A,p,q)
 1. if p is not equal to q do the following
 2. r ← (p+q)/2
 3. Exchange A[(p+r)/2..r] ←→ A[(p+q)/2 +1 ..(r+q)/2].
 4. Rearrange(A,p,r)
 5. Rearrange(A,r+1,q)
 6. return



 On Mon, Aug 1, 2011 at 1:45 PM, Abhishek Gupta gupta.abh...@gmail.comwrote:

 A is an array of size 2n such that first n elements are integers in any
 order and last n elements are characters.
 i.e. A={i1 i2 i3 in c1 c2 c3... cn}
 then we have to rearrange the elements such that final array is
 A ={ i1 c1 i2 c2 .. in cn}


 Example :
 input : A ={ 5,1,4,d,r,a};
 output : A= {5,d,1,r,4,a};

 --
 Abhishek Gupta
 MCA
 NIT Calicut
 Kerela

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




 --
 Regards :
 ROHIT JALAN
 B.E. Graduate,
 Computer Science Department,
 RVCE, Bangalore

  --
 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] Google interview question

2011-07-15 Thread radha krishnan
just hash it

On Fri, Jul 15, 2011 at 6:28 PM, Anand Shastri
anand.shastr...@gmail.com wrote:
 Given a file containing 4,300,000,000  integers, how
 can you find one that appears at least twice

 --
 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] Google interview question

2011-07-15 Thread Anand Shastri
file any way contains integers why do we need hash those integers? why not
use the same integers to index an array.

On Fri, Jul 15, 2011 at 6:36 PM, radha krishnan 
radhakrishnance...@gmail.com wrote:

 just hash it

 On Fri, Jul 15, 2011 at 6:28 PM, Anand Shastri
 anand.shastr...@gmail.com wrote:
  Given a file containing 4,300,000,000  integers, how
  can you find one that appears at least twice
 
  --
  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] Google interview question

2011-07-15 Thread radha krishnan
if number is (131) -1  u declare a 2GB array ?

On Fri, Jul 15, 2011 at 6:59 PM, Anand Shastri
anand.shastr...@gmail.com wrote:
 file any way contains integers why do we need hash those integers? why not
 use the same integers to index an array.

 On Fri, Jul 15, 2011 at 6:36 PM, radha krishnan
 radhakrishnance...@gmail.com wrote:

 just hash it

 On Fri, Jul 15, 2011 at 6:28 PM, Anand Shastri
 anand.shastr...@gmail.com wrote:
  Given a file containing 4,300,000,000  integers, how
  can you find one that appears at least twice
 
  --
  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] Google interview question

2011-07-15 Thread Anand Shastri
File has 4,300,000,000 integers if you hash it will create a distinct hash
for 4,300,000,000 integers.

On Fri, Jul 15, 2011 at 7:09 PM, radha krishnan 
radhakrishnance...@gmail.com wrote:

 if number is (131) -1  u declare a 2GB array ?

 On Fri, Jul 15, 2011 at 6:59 PM, Anand Shastri
  anand.shastr...@gmail.com wrote:
  file any way contains integers why do we need hash those integers? why
 not
  use the same integers to index an array.
 
  On Fri, Jul 15, 2011 at 6:36 PM, radha krishnan
  radhakrishnance...@gmail.com wrote:
 
  just hash it
 
  On Fri, Jul 15, 2011 at 6:28 PM, Anand Shastri
  anand.shastr...@gmail.com wrote:
   Given a file containing 4,300,000,000  integers, how
   can you find one that appears at least twice
  
   --
   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] Google interview question

2011-07-15 Thread radha krishnan
thats the challenge man ! if u are declaring a static Array of 2GB and
u might find the repeated element in second step then memory is waste
!
Thats why hashing ! hashing has complexity of O(n) only !
Instead you can simply use a BBST but complexity is O(n lgn)

On Fri, Jul 15, 2011 at 7:11 PM, Anand Shastri
anand.shastr...@gmail.com wrote:
 File has 4,300,000,000 integers if you hash it will create a distinct hash
 for 4,300,000,000 integers.

 On Fri, Jul 15, 2011 at 7:09 PM, radha krishnan
 radhakrishnance...@gmail.com wrote:

 if number is (131) -1  u declare a 2GB array ?

 On Fri, Jul 15, 2011 at 6:59 PM, Anand Shastri
 anand.shastr...@gmail.com wrote:
  file any way contains integers why do we need hash those integers? why
  not
  use the same integers to index an array.
 
  On Fri, Jul 15, 2011 at 6:36 PM, radha krishnan
  radhakrishnance...@gmail.com wrote:
 
  just hash it
 
  On Fri, Jul 15, 2011 at 6:28 PM, Anand Shastri
  anand.shastr...@gmail.com wrote:
   Given a file containing 4,300,000,000  integers, how
   can you find one that appears at least twice
  
   --
   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.


-- 
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] Google Interview Question

2011-06-05 Thread Nikhil Jindal
Anshu here has given a Perfect soln!
Sunny's code is also correct but is a bit less efficient than anshu's.

Cheers
Nikhil Jindal
http://sites.google.com/site/aboutnikhiljindal/

On Fri, May 27, 2011 at 9:11 PM, anshu mishra anshumishra6...@gmail.comwrote:

 @all go through this code

 #includeiostream
 #includealgorithm

 using namespace std;
 bool compare(int a, int b)
 {
 string u, v;
 u = v = ;
 while (a)
 {
 u += (a % 10 + '0');
 a/=10;
 }
 while (b)
 {
 v += (b % 10 + '0');
 b/=10;
 }
 int i = 0, j = 0;
 reverse(u.begin(), u.end());
 reverse(v.begin(), v.end());
 while (i  u.size() || j  v.size())
 {
 if (i == u.size()) i = 0;
 if (j == v.size()) j = 0;
 for (; i  u.size()  j  v.size(); i++, j++)
 {
 if (u[i] == v[j]) continue;
 return (u[i]  v[j]);
 }
 }
 if (u.size() == v.size()) return true;
 }
 int main()
 {
 int n;
 cin  n;
 int ar[n];
 int i;
 for (i = 0; i  n; i++)
 {
 cin  ar[i];
 }
 sort (ar, ar +n, compare);
 for (i = 0; i  n; i++) cout  ar[i];
 cout  endl;
 return 0;
 }

  --
 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] Google Interview Question

2011-06-05 Thread Nikhil Jindal
@Bhavesh:
Counter case for you:

array = {68, 6867}
u change this array to: {6866, 6867}
then u sort them to get 6867, 6866 and then give the ans as: 686768. While
the correct ans is: 686867

The problem in ur algo is in appending the first digit at the end of each
number. For a correct algo, not just the first digit but the complete number
should be appended.
Hence, to get correct result, you should change the array to : {6868, 6867}.

Hope this makes things clear for you.

Cheers
Nikhil Jindal
http://sites.google.com/site/aboutnikhiljindal/

On Mon, May 30, 2011 at 3:28 PM, Bhavesh agrawal agr.bhav...@gmail.comwrote:

  solution may be


 array ={ 3 ,21 ,9 ,93,17 ,178 ,1,101} (i think i have covered all
 exceptions )

 then ,change this array like 3 , 21222, 9, 93999, 17111, 17811,
 1 , 10111  ( make each number of 5 digit with rest digits same as Ist
 digit )
  then sort this array

 9, 93999,3 21222, 17811,17111, 1, 10111
  and make it with actual numbers

 9,93,3,21,178,17,1,101= 993321178171101

 plz let me know if any case left...

 --
 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] Google Interview Question

2011-06-05 Thread Nikhil Jindal
@Naveen:
Here's a counter case:

162, 16
The next digit(2) is not greater than the last equal digit(6), still 162
comes before 16.

Here, as is done in ashu's algo, the next digit (2) should be compared with
first digit(1) and not the last equal digit(6).

Cheers
Nikhil Jindal
http://sites.google.com/site/aboutnikhiljindal/

On Mon, May 30, 2011 at 12:43 PM, Naveen Agrawal nav.coo...@gmail.comwrote:

 @ shubham

 Your solution need some changes at step 2

 step 1:
sort the given numbers in the decreasing order based on their first
 digit(left most).

 step 2:
if two numbers come out to be equal in the above case  both of
 their next digit exist then sort on the basis of their next digit,
otherwise,
the number whose next digit *is greater than last equal digit will
 come first.(i.e, n=10 m=108  ,as next digit(n-0,m-8) is greater than last
 equal digit(0), so 108 will come first ) *



 Naveen

 --
 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] Google Interview Question

2011-06-05 Thread Wladimir Tavares
Greedy Algorithm:
Sort descending elements using the following order:
A  B are the concatenation of A and B. Following Set the order relation
Between the numeric strings
A B iff A  B B  A

Concatenate all elements in this order set.

To show the correctness of this algorithm need to show that this relation 
is a total order.

The relationship is clearly anti-symmetric and total. It remains to show the
transitivity

Can anybody show that transitivity of this particular order?


Wladimir Araujo Tavares
*Federal University of Ceará

*




On Mon, May 30, 2011 at 10:07 AM, Bhavesh agrawal agr.bhav...@gmail.comwrote:

 @piyush :

  hey buddy, check out carefully i think you missed something.

 my solution says it's 18  -18111
187-18711
 and i think you will count it carefully...

 plz let me know in any case if my solution goes wrong anywhere .



  --
 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] Google Interview Question

2011-05-30 Thread KRQ
but ,when the arr is 78 3
to add 0
78 30
sort: 30 78
ans:378?

2011/5/27 Logic King crazy.logic.k...@gmail.com

 i agree with piyush...can't find the countercase...satisfied with the algo.


 On Fri, May 27, 2011 at 6:58 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote:

 how about adding zeroes at the end of integers to make to equal to the
 integer with maximum number of digits and sort them...

 ex-
 101 10

 adding zeroes..
 101 100

 sort 100 101

 therefore make number as 10110

 100 1

 adding zeroes
 100 100

 therefore number is 1100

 I am not sure of the method.if there is any counter case please do
 suggest...

 On 5/27/11, wujin chen wujinchen...@gmail.com wrote:
  @radha,  i think your solution is wrong.
  for this case: 101,10
  in your solution , the ans is 10101,but the max ans is 10110.
 
  2011/5/27 radha krishnan radhakrishnance...@gmail.com
 
  10100 is max ans
  okay
  convert the numbers to strings and sort based on the first character
  !!!
  if equal do that recursively  and then if length is less give that
  preference !!
  i think this solution ..
  may be this is wrong !!
 
  On Fri, May 27, 2011 at 7:07 PM, wujin chen wujinchen...@gmail.com
 wrote:
 
  @Piyush, how to deal with this case :100 , 10
 
 
  2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com
 
  we can work out if we sort according to the leftmost integer
 
  On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
   are you kidding me. Just simple sort wont work.
  
   On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
   radhakrishnance...@gmail.com wrote:
  
   sort :)
  
  
   On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
  
   Hi all,
  
   Given an array of elements find the largest possible number that
 can
   be formed by using the elements of the array.
  
   eg: 10 9
   ans: 910
  
   2 3 5 78
  
   ans: 78532
  
   100 9
  
   ans: 9100
  
   --
   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.
  
  
 
 
  --
  *Piyush Sinha*
  *IIIT, Allahabad*
  *+91-8792136657*
  *+91-7483122727*
  *https://www.facebook.com/profile.php?id=10655377926 *
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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

Re: [algogeeks] Google Interview Question

2011-05-30 Thread Naveen Agrawal
@ shubham

Your solution need some changes at step 2

step 1:
   sort the given numbers in the decreasing order based on their first
digit(left most).
step 2:
   if two numbers come out to be equal in the above case  both of their
next digit exist then sort on the basis of their next digit,
   otherwise,
   the number whose next digit *is greater than last equal digit will
come first.(i.e, n=10 m=108  ,as next digit(n-0,m-8) is greater than last
equal digit(0), so 108 will come first ) *



Naveen

-- 
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] Google Interview Question

2011-05-30 Thread ankit sambyal
@Nave ::  nice solution  :)  Phoda


Sambyal


On Mon, May 30, 2011 at 12:13 AM, Naveen Agrawal nav.coo...@gmail.comwrote:

 @ shubham

 Your solution need some changes at step 2

 step 1:
sort the given numbers in the decreasing order based on their first
 digit(left most).

 step 2:
if two numbers come out to be equal in the above case  both of
 their next digit exist then sort on the basis of their next digit,
otherwise,
the number whose next digit *is greater than last equal digit will
 come first.(i.e, n=10 m=108  ,as next digit(n-0,m-8) is greater than last
 equal digit(0), so 108 will come first ) *



 Naveen

 --
 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] Google Interview Question

2011-05-30 Thread Sudhir mishra
give some explanation

-- 
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] Google Interview Question

2011-05-30 Thread snehi jain
i guess Sunny  has already mentioned (concatenating the two numbers and
comparing) this technique before, i liked and tried coding it ... it works
perfectly  without comparing the second digit incase the first is same. the
algorithm can run in O(nlogn) taking the best sorting technique , though i
have used the O(n^2)one.
i tried for 5 numbers, one can do it for N numbers too.

@maksym could you explain your logic

int length(int );
int power(int );
int com(int, int );
void swap(int *, int *);
main()
 {
  int a[5],l, j, temp;
  int i ;
  for(i = 0 ;i5;i++)
   {
printf( \n\tEnter the %d number , i+1);
scanf(%d,a[i]);
l =length(a[i]);
}
for (i = 0; i5; i++)
for (j = 0 ; j5;j++)
 {
   temp = com(a[i], a[j]);
if (temp != a[i])
  swap(a+i, a+j);
  }
  for (i =  0 ;i5;i++)
   printf(\n\t%d,a[i]);
   printf(\n\t\t The largest possible number is\n\t );
   for (i = 4 ;i=0;i--)
   printf(%d,a[i]);
   getch();


}

void swap(int *n1, int *n2)
 {
 int temp;
 temp = *n1;
 *n1 = *n2;
 *n2 = temp;
}
int length(int a)
 {
 int len=0,i = 10 ;

 while (a!=0)
  {
   a = a/10;
   len++;
   }
 return len;

}
int com(int a1, int a2)
 {
int l1, l2;
int c,d;
l1 = length(a1);
l2 = length(a2);
c= a1*power(l2) +a2;
d = a2*power(l1)+a1;
  if (cd)
   return a1;
  else
   return a2;
}

 int power(int n)
 {
int i=0, a = 1;
for (i = 0;in;i++)
   a *=10;
return a;
 }


enjoy :)

On Mon, May 30, 2011 at 1:36 PM, Sudhir mishra sudhir08.mis...@gmail.comwrote:

 give some explanation

 --
 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] Google Interview Question

2011-05-30 Thread Maksym Melnychok
some explanation

say we have numbers 2 3 5 78
divide all by something to get 0.2, 0.3, 0.5, 0.78
simple sort will give you 0.78, 0.5, 0.3, 0.2
multiply all numbers to get original ones 78 5 3 2
join 78532

-- 
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] Google Interview Question

2011-05-30 Thread sunny agrawal
@ Maksym Melnychok

Fails i think
some explanation

say we have numbers 1 , 101
divide all by something to get 0.1, 0.101
simple sort will give you 0.101, 0.1
multiply all numbers to get original ones 101,1
join 1011

but correct answer should be 1101, isn't it ??
correct me if i m wrong ??

-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

-- 
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] Google Interview Question

2011-05-30 Thread Maksym Melnychok
possible fix for 100 10 edgecases would be to simply array.map{|x| x*10+1} 
and then get rid of that after sorting

-- 
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] Google Interview Question

2011-05-30 Thread Bhavesh agrawal
 solution may be


array ={ 3 ,21 ,9 ,93,17 ,178 ,1,101} (i think i have covered all exceptions
)

then ,change this array like 3 , 21222, 9, 93999, 17111, 17811,
1 , 10111  ( make each number of 5 digit with rest digits same as Ist
digit )
 then sort this array

9, 93999,3 21222, 17811,17111, 1, 10111
 and make it with actual numbers

9,93,3,21,178,17,1,101= 993321178171101

plz let me know if any case left...

-- 
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] Google Interview Question

2011-05-30 Thread Piyush Sinha
@Bhavesh...

for the inputs 18,187.. apply your method..
18 -- 188
187-- 187

18187 - ur method

18718 - actual

On Mon, May 30, 2011 at 3:28 PM, Bhavesh agrawal agr.bhav...@gmail.comwrote:

  solution may be


 array ={ 3 ,21 ,9 ,93,17 ,178 ,1,101} (i think i have covered all
 exceptions )

 then ,change this array like 3 , 21222, 9, 93999, 17111, 17811,
 1 , 10111  ( make each number of 5 digit with rest digits same as Ist
 digit )
  then sort this array

 9, 93999,3 21222, 17811,17111, 1, 10111
  and make it with actual numbers

 9,93,3,21,178,17,1,101= 993321178171101

 plz let me know if any case left...

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




-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

-- 
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] Google Interview Question

2011-05-30 Thread Maksym Melnychok
@Sunny i explained how to deal with edgecases right after my post

1, 101 - 11, 1011
11, 1011 - 0.11, 0.1011
sort - 0.11, 0.1011
restore - 1, 101
join - 1101

i can't think of any fail examples anymore

-- 
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] Google Interview Question

2011-05-30 Thread snehi jain
@Maksym

what if we have 90 and 9
they become .9 and .9
now what to do to get result as 990 and not 909.

correct me if i am going somewhere wrong?


On Mon, May 30, 2011 at 3:55 PM, Maksym Melnychok keym...@gmail.com wrote:

 @Sunny i explained how to deal with edgecases right after my post

 1, 101 - 11, 1011
 11, 1011 - 0.11, 0.1011
 sort - 0.11, 0.1011
 restore - 1, 101
 join - 1101

 i can't think of any fail examples anymore

 --
 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] Google Interview Question

2011-05-30 Thread Maksym Melnychok
@halo check my previous messages

we multiply every element by 10 and add 1

90, 9 - 901, 91
901, 91 - 0.901, 0.91
sort - 0.91, 0.901
revert - 9, 90
join - 990

-- 
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] Google Interview Question

2011-05-30 Thread snehi jain
ok ... got it thanks ... :)


On Mon, May 30, 2011 at 5:25 PM, Maksym Melnychok keym...@gmail.com wrote:

 @halo check my previous messages

 we multiply every element by 10 and add 1

 90, 9 - 901, 91
 901, 91 - 0.901, 0.91
 sort - 0.91, 0.901
 revert - 9, 90
 join - 990

 --
 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] Google Interview Question

2011-05-30 Thread Bhavesh agrawal
@piyush :

 hey buddy, check out carefully i think you missed something.

my solution says it's 18  -18111
   187-18711
and i think you will count it carefully...

plz let me know in any case if my solution goes wrong anywhere .

-- 
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] Google Interview Question

2011-05-29 Thread Ashish Goel
Radix/bucket sort..

won't that help?

Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652


On Fri, May 27, 2011 at 7:15 PM, adityasir...@gmail.com wrote:

 how about this case:

  9, 100 - 9100
 100 9
 9100

  2, 3, 9, 78 --
  78 9 3 2
 9 78 3 2

 I guess solution should be:-
 sort the array of numbers in an ascending order and then check for the
 first element in the array, if there is any other element greater than it,
 shift all the elements one right and place that element in the left most
 space.


 On Fri, May 27, 2011 at 9:37 AM, wujin chen wujinchen...@gmail.comwrote:

 @Piyush, how to deal with this case :100 , 10


 2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com

 we can work out if we sort according to the leftmost integer

 On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
  are you kidding me. Just simple sort wont work.
 
  On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
  radhakrishnance...@gmail.com wrote:
 
  sort :)
 
 
  On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com wrote:
 
  Hi all,
 
  Given an array of elements find the largest possible number that can
  be formed by using the elements of the array.
 
  eg: 10 9
  ans: 910
 
  2 3 5 78
 
  ans: 78532
 
  100 9
 
  ans: 9100
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 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] Google Interview Question

2011-05-29 Thread Vishal Jain
Can this work...

Lets say I have following numbers
8 9 7 4 2 121 23 21 24 27 35 79 2334 6785

Now repeat the last number to make all the number of equal length...
     1211 2333 2111 2444 2777 3555 7999 2334 6785

Sort the following numbers in descending order.
  7999  6785 ...

Now merge the numbers based on their actual value.
987976785..

I have not testing this entirely, but after seeing solution(Multiplying by
10) at top, I though this might work better.


Thanks  Regards
Vishal Jain
MNo: +91-9540611889
Tweet @jainvis
Blog @ jainvish.blogspot.com
Success taste better when target achieved is bigger.

P *We have a responsibility to the environment.*

*Before printing this e-mail or any other document, let's ask
ourselves whether we need a hard copy.*




On Sun, May 29, 2011 at 12:58 PM, Ashish Goel ashg...@gmail.com wrote:

 Radix/bucket sort..

 won't that help?

 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652



 On Fri, May 27, 2011 at 7:15 PM, adityasir...@gmail.com wrote:

 how about this case:

  9, 100 - 9100
 100 9
 9100

  2, 3, 9, 78 --
  78 9 3 2
 9 78 3 2

 I guess solution should be:-
 sort the array of numbers in an ascending order and then check for the
 first element in the array, if there is any other element greater than it,
 shift all the elements one right and place that element in the left most
 space.


 On Fri, May 27, 2011 at 9:37 AM, wujin chen wujinchen...@gmail.comwrote:

 @Piyush, how to deal with this case :100 , 10


 2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com

 we can work out if we sort according to the leftmost integer

 On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
  are you kidding me. Just simple sort wont work.
 
  On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
  radhakrishnance...@gmail.com wrote:
 
  sort :)
 
 
  On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
 
  Hi all,
 
  Given an array of elements find the largest possible number that can
  be formed by using the elements of the array.
 
  eg: 10 9
  ans: 910
 
  2 3 5 78
 
  ans: 78532
 
  100 9
 
  ans: 9100
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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

Re: [algogeeks] Google Interview Question

2011-05-27 Thread radha krishnan
sort :)

On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com wrote:

 Hi all,

 Given an array of elements find the largest possible number that can
 be formed by using the elements of the array.

 eg: 10 9
 ans: 910

 2 3 5 78

 ans: 78532

 100 9

 ans: 9100

 --
 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] Google Interview Question

2011-05-27 Thread adityasirohi
are you kidding me. Just simple sort wont work.

On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
radhakrishnance...@gmail.com wrote:

 sort :)


 On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com wrote:

 Hi all,

 Given an array of elements find the largest possible number that can
 be formed by using the elements of the array.

 eg: 10 9
 ans: 910

 2 3 5 78

 ans: 78532

 100 9

 ans: 9100

 --
 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] Google Interview Question

2011-05-27 Thread Piyush Sinha
we can work out if we sort according to the leftmost integer

On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
 are you kidding me. Just simple sort wont work.

 On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
 radhakrishnance...@gmail.com wrote:

 sort :)


 On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com wrote:

 Hi all,

 Given an array of elements find the largest possible number that can
 be formed by using the elements of the array.

 eg: 10 9
 ans: 910

 2 3 5 78

 ans: 78532

 100 9

 ans: 9100

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




-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

-- 
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] Google Interview Question

2011-05-27 Thread radha krishnan
Haha !! Any counter  case against sort ? ?? ? :P

On Fri, May 27, 2011 at 7:02 PM, adityasir...@gmail.com wrote:

 are you kidding me. Just simple sort wont work.

 On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
 radhakrishnance...@gmail.com wrote:

 sort :)


 On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com wrote:

 Hi all,

 Given an array of elements find the largest possible number that can
 be formed by using the elements of the array.

 eg: 10 9
 ans: 910

 2 3 5 78

 ans: 78532

 100 9

 ans: 9100

 --
 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] Google Interview Question

2011-05-27 Thread wujin chen
@Piyush, how to deal with this case :100 , 10

2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com

 we can work out if we sort according to the leftmost integer

 On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
  are you kidding me. Just simple sort wont work.
 
  On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
  radhakrishnance...@gmail.com wrote:
 
  sort :)
 
 
  On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com wrote:
 
  Hi all,
 
  Given an array of elements find the largest possible number that can
  be formed by using the elements of the array.
 
  eg: 10 9
  ans: 910
 
  2 3 5 78
 
  ans: 78532
 
  100 9
 
  ans: 9100
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 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] Google Interview Question

2011-05-27 Thread adityasirohi
how about this case:

 9, 100 - 9100
100 9
9100

 2, 3, 9, 78 --
 78 9 3 2
9 78 3 2

I guess solution should be:-
sort the array of numbers in an ascending order and then check for the first
element in the array, if there is any other element greater than it, shift
all the elements one right and place that element in the left most space.


On Fri, May 27, 2011 at 9:37 AM, wujin chen wujinchen...@gmail.com wrote:

 @Piyush, how to deal with this case :100 , 10


 2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com

 we can work out if we sort according to the leftmost integer

 On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
  are you kidding me. Just simple sort wont work.
 
  On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
  radhakrishnance...@gmail.com wrote:
 
  sort :)
 
 
  On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com wrote:
 
  Hi all,
 
  Given an array of elements find the largest possible number that can
  be formed by using the elements of the array.
 
  eg: 10 9
  ans: 910
 
  2 3 5 78
 
  ans: 78532
 
  100 9
 
  ans: 9100
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 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] Google Interview Question

2011-05-27 Thread Piyush Sinha
how about adding zeroes at the end of integers to make to equal to the
integer with maximum number of digits and sort them...

ex-
101 10

adding zeroes..
101 100

sort 100 101

therefore make number as 10110

100 1

adding zeroes
100 100

therefore number is 1100

I am not sure of the method.if there is any counter case please do
suggest...

On 5/27/11, wujin chen wujinchen...@gmail.com wrote:
 @radha,  i think your solution is wrong.
 for this case: 101,10
 in your solution , the ans is 10101,but the max ans is 10110.

 2011/5/27 radha krishnan radhakrishnance...@gmail.com

 10100 is max ans
 okay
 convert the numbers to strings and sort based on the first character
 !!!
 if equal do that recursively  and then if length is less give that
 preference !!
 i think this solution ..
 may be this is wrong !!

 On Fri, May 27, 2011 at 7:07 PM, wujin chen wujinchen...@gmail.comwrote:

 @Piyush, how to deal with this case :100 , 10


 2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com

 we can work out if we sort according to the leftmost integer

 On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
  are you kidding me. Just simple sort wont work.
 
  On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
  radhakrishnance...@gmail.com wrote:
 
  sort :)
 
 
  On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com wrote:
 
  Hi all,
 
  Given an array of elements find the largest possible number that can
  be formed by using the elements of the array.
 
  eg: 10 9
  ans: 910
 
  2 3 5 78
 
  ans: 78532
 
  100 9
 
  ans: 9100
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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




-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

-- 
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] Google Interview Question

2011-05-27 Thread Logic King
i agree with piyush...can't find the countercase...satisfied with the algo.

On Fri, May 27, 2011 at 6:58 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote:

 how about adding zeroes at the end of integers to make to equal to the
 integer with maximum number of digits and sort them...

 ex-
 101 10

 adding zeroes..
 101 100

 sort 100 101

 therefore make number as 10110

 100 1

 adding zeroes
 100 100

 therefore number is 1100

 I am not sure of the method.if there is any counter case please do
 suggest...

 On 5/27/11, wujin chen wujinchen...@gmail.com wrote:
  @radha,  i think your solution is wrong.
  for this case: 101,10
  in your solution , the ans is 10101,but the max ans is 10110.
 
  2011/5/27 radha krishnan radhakrishnance...@gmail.com
 
  10100 is max ans
  okay
  convert the numbers to strings and sort based on the first character
  !!!
  if equal do that recursively  and then if length is less give that
  preference !!
  i think this solution ..
  may be this is wrong !!
 
  On Fri, May 27, 2011 at 7:07 PM, wujin chen wujinchen...@gmail.com
 wrote:
 
  @Piyush, how to deal with this case :100 , 10
 
 
  2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com
 
  we can work out if we sort according to the leftmost integer
 
  On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
   are you kidding me. Just simple sort wont work.
  
   On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
   radhakrishnance...@gmail.com wrote:
  
   sort :)
  
  
   On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
  
   Hi all,
  
   Given an array of elements find the largest possible number that
 can
   be formed by using the elements of the array.
  
   eg: 10 9
   ans: 910
  
   2 3 5 78
  
   ans: 78532
  
   100 9
  
   ans: 9100
  
   --
   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.
  
  
 
 
  --
  *Piyush Sinha*
  *IIIT, Allahabad*
  *+91-8792136657*
  *+91-7483122727*
  *https://www.facebook.com/profile.php?id=10655377926 *
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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

Re: [algogeeks] Google Interview Question

2011-05-27 Thread • » νιρυℓ « •
Take input as vector of string or array of string
sort the vector
print from end to beginning

On Fri, May 27, 2011 at 7:51 PM, Logic King crazy.logic.k...@gmail.comwrote:

 i agree with piyush...can't find the countercase...satisfied with the algo.


 On Fri, May 27, 2011 at 6:58 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote:

 how about adding zeroes at the end of integers to make to equal to the
 integer with maximum number of digits and sort them...

 ex-
 101 10

 adding zeroes..
 101 100

 sort 100 101

 therefore make number as 10110

 100 1

 adding zeroes
 100 100

 therefore number is 1100

 I am not sure of the method.if there is any counter case please do
 suggest...

 On 5/27/11, wujin chen wujinchen...@gmail.com wrote:
  @radha,  i think your solution is wrong.
  for this case: 101,10
  in your solution , the ans is 10101,but the max ans is 10110.
 
  2011/5/27 radha krishnan radhakrishnance...@gmail.com
 
  10100 is max ans
  okay
  convert the numbers to strings and sort based on the first character
  !!!
  if equal do that recursively  and then if length is less give that
  preference !!
  i think this solution ..
  may be this is wrong !!
 
  On Fri, May 27, 2011 at 7:07 PM, wujin chen wujinchen...@gmail.com
 wrote:
 
  @Piyush, how to deal with this case :100 , 10
 
 
  2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com
 
  we can work out if we sort according to the leftmost integer
 
  On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
   are you kidding me. Just simple sort wont work.
  
   On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
   radhakrishnance...@gmail.com wrote:
  
   sort :)
  
  
   On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
  
   Hi all,
  
   Given an array of elements find the largest possible number that
 can
   be formed by using the elements of the array.
  
   eg: 10 9
   ans: 910
  
   2 3 5 78
  
   ans: 78532
  
   100 9
  
   ans: 9100
  
   --
   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.
  
  
 
 
  --
  *Piyush Sinha*
  *IIIT, Allahabad*
  *+91-8792136657*
  *+91-7483122727*
  *https://www.facebook.com/profile.php?id=10655377926 *
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

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

Re: [algogeeks] Google Interview Question

2011-05-27 Thread • » νιρυℓ « •
@Piyush Sinha,
what about  9, 801

2011/5/27 • » νιρυℓ « • vipulmehta.1...@gmail.com

 Take input as vector of string or array of string
 sort the vector
 print from end to beginning


 On Fri, May 27, 2011 at 7:51 PM, Logic King crazy.logic.k...@gmail.comwrote:

 i agree with piyush...can't find the countercase...satisfied with the
 algo.


 On Fri, May 27, 2011 at 6:58 AM, Piyush Sinha 
 ecstasy.piy...@gmail.comwrote:

 how about adding zeroes at the end of integers to make to equal to the
 integer with maximum number of digits and sort them...

 ex-
 101 10

 adding zeroes..
 101 100

 sort 100 101

 therefore make number as 10110

 100 1

 adding zeroes
 100 100

 therefore number is 1100

 I am not sure of the method.if there is any counter case please do
 suggest...

 On 5/27/11, wujin chen wujinchen...@gmail.com wrote:
  @radha,  i think your solution is wrong.
  for this case: 101,10
  in your solution , the ans is 10101,but the max ans is 10110.
 
  2011/5/27 radha krishnan radhakrishnance...@gmail.com
 
  10100 is max ans
  okay
  convert the numbers to strings and sort based on the first character
  !!!
  if equal do that recursively  and then if length is less give that
  preference !!
  i think this solution ..
  may be this is wrong !!
 
  On Fri, May 27, 2011 at 7:07 PM, wujin chen wujinchen...@gmail.com
 wrote:
 
  @Piyush, how to deal with this case :100 , 10
 
 
  2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com
 
  we can work out if we sort according to the leftmost integer
 
  On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
   are you kidding me. Just simple sort wont work.
  
   On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
   radhakrishnance...@gmail.com wrote:
  
   sort :)
  
  
   On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
  
   Hi all,
  
   Given an array of elements find the largest possible number that
 can
   be formed by using the elements of the array.
  
   eg: 10 9
   ans: 910
  
   2 3 5 78
  
   ans: 78532
  
   100 9
  
   ans: 9100
  
   --
   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.
  
  
 
 
  --
  *Piyush Sinha*
  *IIIT, Allahabad*
  *+91-8792136657*
  *+91-7483122727*
  *https://www.facebook.com/profile.php?id=10655377926 *
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 

Re: [algogeeks] Google Interview Question

2011-05-27 Thread Aakash Johari
@vipul: try for 100 and 10

2011/5/27 • » νιρυℓ « • vipulmehta.1...@gmail.com

 @Piyush Sinha,
 what about  9, 801

 2011/5/27 • » νιρυℓ « • vipulmehta.1...@gmail.com

 Take input as vector of string or array of string
 sort the vector
 print from end to beginning


 On Fri, May 27, 2011 at 7:51 PM, Logic King 
 crazy.logic.k...@gmail.comwrote:

 i agree with piyush...can't find the countercase...satisfied with the
 algo.


 On Fri, May 27, 2011 at 6:58 AM, Piyush Sinha 
 ecstasy.piy...@gmail.comwrote:

 how about adding zeroes at the end of integers to make to equal to the
 integer with maximum number of digits and sort them...

 ex-
 101 10

 adding zeroes..
 101 100

 sort 100 101

 therefore make number as 10110

 100 1

 adding zeroes
 100 100

 therefore number is 1100

 I am not sure of the method.if there is any counter case please do
 suggest...

 On 5/27/11, wujin chen wujinchen...@gmail.com wrote:
  @radha,  i think your solution is wrong.
  for this case: 101,10
  in your solution , the ans is 10101,but the max ans is 10110.
 
  2011/5/27 radha krishnan radhakrishnance...@gmail.com
 
  10100 is max ans
  okay
  convert the numbers to strings and sort based on the first character
  !!!
  if equal do that recursively  and then if length is less give that
  preference !!
  i think this solution ..
  may be this is wrong !!
 
  On Fri, May 27, 2011 at 7:07 PM, wujin chen wujinchen...@gmail.com
 wrote:
 
  @Piyush, how to deal with this case :100 , 10
 
 
  2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com
 
  we can work out if we sort according to the leftmost integer
 
  On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
   are you kidding me. Just simple sort wont work.
  
   On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
   radhakrishnance...@gmail.com wrote:
  
   sort :)
  
  
   On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
  
   Hi all,
  
   Given an array of elements find the largest possible number
 that can
   be formed by using the elements of the array.
  
   eg: 10 9
   ans: 910
  
   2 3 5 78
  
   ans: 78532
  
   100 9
  
   ans: 9100
  
   --
   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.
  
  
 
 
  --
  *Piyush Sinha*
  *IIIT, Allahabad*
  *+91-8792136657*
  *+91-7483122727*
  *https://www.facebook.com/profile.php?id=10655377926 *
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 You received 

Re: [algogeeks] Google Interview Question

2011-05-27 Thread Arpit Mittal
@piyush :

for 1, 100

you did
100,100
then sort
 result 100,100

 so u said ans is 1100 but it could also be 1001 as 100=100...

correct me if i am wrong?

On Fri, May 27, 2011 at 7:39 AM, Aakash Johari aakashj@gmail.comwrote:

 @vipul: try for 100 and 10


 2011/5/27 • » νιρυℓ « • vipulmehta.1...@gmail.com

 @Piyush Sinha,
 what about  9, 801

 2011/5/27 • » νιρυℓ « • vipulmehta.1...@gmail.com

 Take input as vector of string or array of string
 sort the vector
 print from end to beginning


 On Fri, May 27, 2011 at 7:51 PM, Logic King 
 crazy.logic.k...@gmail.comwrote:

 i agree with piyush...can't find the countercase...satisfied with the
 algo.


 On Fri, May 27, 2011 at 6:58 AM, Piyush Sinha ecstasy.piy...@gmail.com
  wrote:

 how about adding zeroes at the end of integers to make to equal to the
 integer with maximum number of digits and sort them...

 ex-
 101 10

 adding zeroes..
 101 100

 sort 100 101

 therefore make number as 10110

 100 1

 adding zeroes
 100 100

 therefore number is 1100

 I am not sure of the method.if there is any counter case please do
 suggest...

 On 5/27/11, wujin chen wujinchen...@gmail.com wrote:
  @radha,  i think your solution is wrong.
  for this case: 101,10
  in your solution , the ans is 10101,but the max ans is 10110.
 
  2011/5/27 radha krishnan radhakrishnance...@gmail.com
 
  10100 is max ans
  okay
  convert the numbers to strings and sort based on the first character
  !!!
  if equal do that recursively  and then if length is less give that
  preference !!
  i think this solution ..
  may be this is wrong !!
 
  On Fri, May 27, 2011 at 7:07 PM, wujin chen wujinchen...@gmail.com
 wrote:
 
  @Piyush, how to deal with this case :100 , 10
 
 
  2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com
 
  we can work out if we sort according to the leftmost integer
 
  On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com
 wrote:
   are you kidding me. Just simple sort wont work.
  
   On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
   radhakrishnance...@gmail.com wrote:
  
   sort :)
  
  
   On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
  
   Hi all,
  
   Given an array of elements find the largest possible number
 that can
   be formed by using the elements of the array.
  
   eg: 10 9
   ans: 910
  
   2 3 5 78
  
   ans: 78532
  
   100 9
  
   ans: 9100
  
   --
   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.
  
  
 
 
  --
  *Piyush Sinha*
  *IIIT, Allahabad*
  *+91-8792136657*
  *+91-7483122727*
  *https://www.facebook.com/profile.php?id=10655377926 *
 
  --
  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 

Re: [algogeeks] Google Interview Question

2011-05-27 Thread • » νιρυℓ « •
@Aakash, yeah missed that, overriding default string comparator while
sorting will do that.

On Fri, May 27, 2011 at 8:11 PM, Arpit Mittal mrmittalro...@gmail.comwrote:

 @piyush :

 for 1, 100

 you did
 100,100
 then sort
  result 100,100

  so u said ans is 1100 but it could also be 1001 as 100=100...

 correct me if i am wrong?


 On Fri, May 27, 2011 at 7:39 AM, Aakash Johari aakashj@gmail.comwrote:

 @vipul: try for 100 and 10


 2011/5/27 • » νιρυℓ « • vipulmehta.1...@gmail.com

 @Piyush Sinha,
 what about  9, 801

 2011/5/27 • » νιρυℓ « • vipulmehta.1...@gmail.com

 Take input as vector of string or array of string
 sort the vector
 print from end to beginning


 On Fri, May 27, 2011 at 7:51 PM, Logic King crazy.logic.k...@gmail.com
  wrote:

 i agree with piyush...can't find the countercase...satisfied with the
 algo.


 On Fri, May 27, 2011 at 6:58 AM, Piyush Sinha 
 ecstasy.piy...@gmail.com wrote:

 how about adding zeroes at the end of integers to make to equal to the
 integer with maximum number of digits and sort them...

 ex-
 101 10

 adding zeroes..
 101 100

 sort 100 101

 therefore make number as 10110

 100 1

 adding zeroes
 100 100

 therefore number is 1100

 I am not sure of the method.if there is any counter case please do
 suggest...

 On 5/27/11, wujin chen wujinchen...@gmail.com wrote:
  @radha,  i think your solution is wrong.
  for this case: 101,10
  in your solution , the ans is 10101,but the max ans is 10110.
 
  2011/5/27 radha krishnan radhakrishnance...@gmail.com
 
  10100 is max ans
  okay
  convert the numbers to strings and sort based on the first
 character
  !!!
  if equal do that recursively  and then if length is less give that
  preference !!
  i think this solution ..
  may be this is wrong !!
 
  On Fri, May 27, 2011 at 7:07 PM, wujin chen 
 wujinchen...@gmail.comwrote:
 
  @Piyush, how to deal with this case :100 , 10
 
 
  2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com
 
  we can work out if we sort according to the leftmost integer
 
  On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com
 wrote:
   are you kidding me. Just simple sort wont work.
  
   On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
   radhakrishnance...@gmail.com wrote:
  
   sort :)
  
  
   On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
  
   Hi all,
  
   Given an array of elements find the largest possible number
 that can
   be formed by using the elements of the array.
  
   eg: 10 9
   ans: 910
  
   2 3 5 78
  
   ans: 78532
  
   100 9
  
   ans: 9100
  
   --
   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.
  
  
 
 
  --
  *Piyush Sinha*
  *IIIT, Allahabad*
  *+91-8792136657*
  *+91-7483122727*
  *https://www.facebook.com/profile.php?id=10655377926 *
 
  --
  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 

Re: [algogeeks] Google Interview Question

2011-05-27 Thread anshu mishra
@all go through this code

#includeiostream
#includealgorithm

using namespace std;
bool compare(int a, int b)
{
string u, v;
u = v = ;
while (a)
{
u += (a % 10 + '0');
a/=10;
}
while (b)
{
v += (b % 10 + '0');
b/=10;
}
int i = 0, j = 0;
reverse(u.begin(), u.end());
reverse(v.begin(), v.end());
while (i  u.size() || j  v.size())
{
if (i == u.size()) i = 0;
if (j == v.size()) j = 0;
for (; i  u.size()  j  v.size(); i++, j++)
{
if (u[i] == v[j]) continue;
return (u[i]  v[j]);
}
}
if (u.size() == v.size()) return true;
}
int main()
{
int n;
cin  n;
int ar[n];
int i;
for (i = 0; i  n; i++)
{
cin  ar[i];
}
sort (ar, ar +n, compare);
for (i = 0; i  n; i++) cout  ar[i];
cout  endl;
return 0;
}

-- 
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] Google Interview Question

2011-05-27 Thread Supraja Jayakumar
Hi

Isnt this the Kadane's (largest subarray) problem ?

Rgds
Supraja J

On Fri, May 27, 2011 at 9:41 AM, anshu mishra anshumishra6...@gmail.comwrote:

 @all go through this code

 #includeiostream
 #includealgorithm

 using namespace std;
 bool compare(int a, int b)
 {
 string u, v;
 u = v = ;
 while (a)
 {
 u += (a % 10 + '0');
 a/=10;
 }
 while (b)
 {
 v += (b % 10 + '0');
 b/=10;
 }
 int i = 0, j = 0;
 reverse(u.begin(), u.end());
 reverse(v.begin(), v.end());
 while (i  u.size() || j  v.size())
 {
 if (i == u.size()) i = 0;
 if (j == v.size()) j = 0;
 for (; i  u.size()  j  v.size(); i++, j++)
 {
 if (u[i] == v[j]) continue;
 return (u[i]  v[j]);
 }
 }
 if (u.size() == v.size()) return true;
 }
 int main()
 {
 int n;
 cin  n;
 int ar[n];
 int i;
 for (i = 0; i  n; i++)
 {
 cin  ar[i];
 }
 sort (ar, ar +n, compare);
 for (i = 0; i  n; i++) cout  ar[i];
 cout  endl;
 return 0;
 }

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




-- 
U

-- 
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] Google Interview Question

2011-05-27 Thread • » νιρυℓ « •
Kadane's algorithm is considers subarray sum, we are considering
concatenation here.

On Fri, May 27, 2011 at 9:45 PM, Supraja Jayakumar suprajasank...@gmail.com
 wrote:

 Hi

 Isnt this the Kadane's (largest subarray) problem ?

 Rgds
 Supraja J

 On Fri, May 27, 2011 at 9:41 AM, anshu mishra 
 anshumishra6...@gmail.comwrote:

 @all go through this code

 #includeiostream
 #includealgorithm

 using namespace std;
 bool compare(int a, int b)
 {
 string u, v;
 u = v = ;
 while (a)
 {
 u += (a % 10 + '0');
 a/=10;
 }
 while (b)
 {
 v += (b % 10 + '0');
 b/=10;
 }
 int i = 0, j = 0;
 reverse(u.begin(), u.end());
 reverse(v.begin(), v.end());
 while (i  u.size() || j  v.size())
 {
 if (i == u.size()) i = 0;
 if (j == v.size()) j = 0;
 for (; i  u.size()  j  v.size(); i++, j++)
 {
 if (u[i] == v[j]) continue;
 return (u[i]  v[j]);
 }
 }
 if (u.size() == v.size()) return true;
 }
 int main()
 {
 int n;
 cin  n;
 int ar[n];
 int i;
 for (i = 0; i  n; i++)
 {
 cin  ar[i];
 }
 sort (ar, ar +n, compare);
 for (i = 0; i  n; i++) cout  ar[i];
 cout  endl;
 return 0;
 }

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




 --
 U

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




-- 
Regards,
Vipul

-- 
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] Google Interview Question

2011-05-27 Thread ankit sambyal
@Piyush:  try 97,8,9
acc. to ur algo,  adding 0s:   97,80,90
then sorting : 97,90,80
so final ans acc. to ur algo: 9798
whereas the correct ans is : 9897


Ankit
BITS Pilani


On Fri, May 27, 2011 at 6:58 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote:

 how about adding zeroes at the end of integers to make to equal to the
 integer with maximum number of digits and sort them...

 ex-
 101 10

 adding zeroes..
 101 100

 sort 100 101

 therefore make number as 10110

 100 1

 adding zeroes
 100 100

 therefore number is 1100

 I am not sure of the method.if there is any counter case please do
 suggest...

 On 5/27/11, wujin chen wujinchen...@gmail.com wrote:
  @radha,  i think your solution is wrong.
  for this case: 101,10
  in your solution , the ans is 10101,but the max ans is 10110.
 
  2011/5/27 radha krishnan radhakrishnance...@gmail.com
 
  10100 is max ans
  okay
  convert the numbers to strings and sort based on the first character
  !!!
  if equal do that recursively  and then if length is less give that
  preference !!
  i think this solution ..
  may be this is wrong !!
 
  On Fri, May 27, 2011 at 7:07 PM, wujin chen wujinchen...@gmail.com
 wrote:
 
  @Piyush, how to deal with this case :100 , 10
 
 
  2011/5/27 Piyush Sinha ecstasy.piy...@gmail.com
 
  we can work out if we sort according to the leftmost integer
 
  On 5/27/11, adityasir...@gmail.com adityasir...@gmail.com wrote:
   are you kidding me. Just simple sort wont work.
  
   On Fri, May 27, 2011 at 9:31 AM, radha krishnan 
   radhakrishnance...@gmail.com wrote:
  
   sort :)
  
  
   On Fri, May 27, 2011 at 6:57 PM, ross jagadish1...@gmail.com
 wrote:
  
   Hi all,
  
   Given an array of elements find the largest possible number that
 can
   be formed by using the elements of the array.
  
   eg: 10 9
   ans: 910
  
   2 3 5 78
  
   ans: 78532
  
   100 9
  
   ans: 9100
  
   --
   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.
  
  
 
 
  --
  *Piyush Sinha*
  *IIIT, Allahabad*
  *+91-8792136657*
  *+91-7483122727*
  *https://www.facebook.com/profile.php?id=10655377926 *
 
  --
  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.
 
 


 --
 *Piyush Sinha*
 *IIIT, Allahabad*
 *+91-8792136657*
 *+91-7483122727*
 *https://www.facebook.com/profile.php?id=10655377926 *

 --
 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] Google Interview Question

2011-05-27 Thread shubham
check whether these steps work:

step 1:
sort the given numbers in the decreasing order based on their first 
digit.
step 2:
if two numbers come out to be equal in the above case  both of 
their next digit exist then sort on the basis of their next digit, otherwise 
the number
whose next digit doesnot exist should be placed before the other 
number.
step 3:
   concatenate these numbers.

e.g.

(0,1,10,100) sorting it gives: 1,10,100,0 = 1101000
(97,8,9) sorting gives: 9,97,8 = 9978

correct me if i'm wrong.

Shubham

-- 
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] Google Interview Question

2011-05-27 Thread • » νιρυℓ « •
@shubham, 10 101 ??

On Fri, May 27, 2011 at 11:41 PM, shubham shubh2...@gmail.com wrote:

 check whether these steps work:

 step 1:
 sort the given numbers in the decreasing order based on their first
 digit.
 step 2:
 if two numbers come out to be equal in the above case  both of
 their next digit exist then sort on the basis of their next digit, otherwise
 the number
 whose next digit doesnot exist should be placed before the other
 number.
 step 3:
concatenate these numbers.

 e.g.

 (0,1,10,100) sorting it gives: 1,10,100,0 = 1101000
 (97,8,9) sorting gives: 9,97,8 = 9978

 correct me if i'm wrong.

 Shubham

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




-- 
Regards,
Vipul

-- 
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] Google Interview Question

2011-05-27 Thread ankit sambyal
@shubam: won't work
   try following test case:  8,89,9

Ankit Sambyal



On Fri, May 27, 2011 at 11:11 AM, shubham shubh2...@gmail.com wrote:

 check whether these steps work:

 step 1:
 sort the given numbers in the decreasing order based on their first
 digit.
 step 2:
 if two numbers come out to be equal in the above case  both of
 their next digit exist then sort on the basis of their next digit, otherwise
 the number
 whose next digit doesnot exist should be placed before the other
 number.
 step 3:
concatenate these numbers.

 e.g.

 (0,1,10,100) sorting it gives: 1,10,100,0 = 1101000
 (97,8,9) sorting gives: 9,97,8 = 9978

 correct me if i'm wrong.

 Shubham

 --
 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] Google Interview Question

2011-05-27 Thread srajan dongre
@ankit sambyal.i think d rite answer will be 9978 in dat case.



On Fri, May 27, 2011 at 11:50 PM, ankit sambyal ankitsamb...@gmail.comwrote:

 @shubam: won't work
try following test case:  8,89,9

 Ankit Sambyal



 On Fri, May 27, 2011 at 11:11 AM, shubham shubh2...@gmail.com wrote:

 check whether these steps work:

 step 1:
 sort the given numbers in the decreasing order based on their
 first digit.
 step 2:
 if two numbers come out to be equal in the above case  both of
 their next digit exist then sort on the basis of their next digit, otherwise
 the number
 whose next digit doesnot exist should be placed before the other
 number.
 step 3:
concatenate these numbers.

 e.g.

 (0,1,10,100) sorting it gives: 1,10,100,0 = 1101000
 (97,8,9) sorting gives: 9,97,8 = 9978

 correct me if i'm wrong.

 Shubham

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




-- 
--

Srajan Dongre
||nd year  CSI (dual degree)
Indian Institute of Technology , Roorkee
Uttrakhand , India
pin code--247667

-- 
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] Google Interview Question

2011-05-27 Thread ankit sambyal
@srajan: ya , i made a mistake...the correct ans  will of-course be 9978




On Fri, May 27, 2011 at 12:11 PM, srajan dongre srajan.don...@gmail.comwrote:

 @ankit sambyal.i think d rite answer will be 9978 in dat case.




 On Fri, May 27, 2011 at 11:50 PM, ankit sambyal ankitsamb...@gmail.comwrote:

 @shubam: won't work
try following test case:  8,89,9

 Ankit Sambyal



 On Fri, May 27, 2011 at 11:11 AM, shubham shubh2...@gmail.com wrote:

 check whether these steps work:

 step 1:
 sort the given numbers in the decreasing order based on their
 first digit.
 step 2:
 if two numbers come out to be equal in the above case  both of
 their next digit exist then sort on the basis of their next digit, otherwise
 the number
 whose next digit doesnot exist should be placed before the other
 number.
 step 3:
concatenate these numbers.

 e.g.

 (0,1,10,100) sorting it gives: 1,10,100,0 = 1101000
 (97,8,9) sorting gives: 9,97,8 = 9978

 correct me if i'm wrong.

 Shubham

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




 --
 --

 Srajan Dongre
 ||nd year  CSI (dual degree)
 Indian Institute of Technology , Roorkee
 Uttrakhand , India
 pin code--247667


  --
 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] GOOGLE INTERVIEW QUESTION

2011-05-10 Thread Senthil S
Hello Anders Ma .. for inputs like iiestseig (just a random string) your
code will not produce the correct output .. cos the best possible way to
split these strings is {i,iestsei,g} .. But your code will produce
{ii,este,i,g} as output .. so when there are overlapping palindromes
your code wont produce the correct output .. please look into it ..

On Tue, May 10, 2011 at 8:03 AM, Anders Ma xuejiao...@gmail.com wrote:

 #include stdio.h
 #include string.h

 int is_palindrome(char* string, int start, int end)
 {
int i = start, j = end;

while (start = end) {
if (string[start++] != string[end--])
return 0;
}

/* print */
printf([%d,%d] , i, j);
while ( i = j)
printf(%c, string[i++]);
printf(\n);

return 1;
 }

 int main(int argc, char** argv)
 {
int i, j, k;
 int len, rescan;
char demo[] = madamimadam;
 char *p;

if (argc != 2) {
printf(usage padin (string)\n);
return 0;
}
p = argv[1];

 do {
rescan = 0;
len = strlen(p);
for (i = 0; i  len  rescan == 0; i++) {
 for (j = i, k = len; j = k; k--)
if (is_palindrome(p, j, k)) {
p += k - j + 1;
 rescan = 1;
break;
}
}
} while (rescan);

return 0;
 }
 anders@ubuntu:~/c$ gcc palindrome.c -o palin
 anders@ubuntu:~/c$ ./palin helloworld
 [0,0] h
 [0,0] e
 [0,1] ll
 [0,2] owo
 [0,0] r
 [0,0] l
 [0,0] d
 anders@ubuntu:~/c$ ./palin madamimadam
 [0,10] madamimadam
 anders@ubuntu:~/c$ ./palin andersma
 [0,0] a
 [0,0] n
 [0,0] d
 [0,0] e
 [0,0] r
 [0,0] s
 [0,0] m
 [0,0] a


 On Tue, May 10, 2011 at 10:11 AM, oldman fenghaungyuyi...@gmail.com
 wrote:
  I agree with Anders Ma's point,but in my opinion, using goto is risky in
 a
  import interview
 
  On Tue, May 10, 2011 at 9:52 AM, Anders Ma xuejiao...@gmail.com wrote:
 
   sometimes we need goto, goto is not so evil.
 
  On Tue, May 10, 2011 at 2:49 AM, Manjeet Chayel
  chayel.manj...@gmail.com wrote:
   Dont use goto... its not good to have it.
  
   On Mon, May 9, 2011 at 2:44 PM, Anders Ma xuejiao...@gmail.com
 wrote:
  
   #include stdio.h
   #include string.h
  
   int is_palindrome(char* string, int start, int end)
   {
  int i = start, j = end;
  
  while (start = end) {
  if (string[start++] != string[end--])
  return 0;
  }
  
  /* print */
  printf([%d,%d] , i, j);
  while ( i = j)
  printf(%c, string[i++]);
  printf(\n);
  
  return 1;
   }
  
   int main(int argc, char** argv)
   {
  int i, j, k;
  int len;
  char *p;
  
  if (argc != 2) {
  printf(usage padin (string)\n);
  return 0;
  }
  p = argv[1];
   BEGIN:
  
  len = strlen(p);
  for (i = 0; i  len; i++) {
  for (j = i, k = len; j = k; k--)
  if (is_palindrome(p, j, k)) {
  p += k - j + 1;
  goto BEGIN;
  }
  }
  
  return 0;
   }
  
   anders@ubuntu:~/c$ ./palin helloworld
   [0,0] h
   [0,0] e
   [0,1] ll
   [0,2] owo
   [0,0] r
   [0,0] l
   [0,0] d
   anders@ubuntu:~/c$ ./palin madamamadam
   [0,10] madamamadam
   anders@ubuntu:~/c$
  
  
  
   On Fri, May 6, 2011 at 8:58 PM, sourabh jakhar
   sourabhjak...@gmail.com
   wrote:
   
   
On Fri, May 6, 2011 at 4:23 PM, sourabh jakhar
sourabhjak...@gmail.com
wrote:
   
You are given a large string. You need to cut the string into
 chunks
such
that each substring that you get is a palindrome. Remember that
 each
1
length string is always a palindrome. You need to find the minimum
number of
cuts that you need to make such that each substring is a
 palindrome.
   
--
SOURABH JAKHAR,(CSE)(3 year)
ROOM NO 167 ,
TILAK,HOSTEL
'MNNIT ALLAHABAD
   
The Law of Win says, Let's not do it your way or my way; let's do
it
the
best way.
   
--
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.
   
   
   
--
SOURABH JAKHAR,(CSE)(3 year)
ROOM NO 167 ,
TILAK,HOSTEL
'MNNIT ALLAHABAD
   
The Law of Win says, Let's not do it your way or my way; let's do
 it
the
 

Re: [algogeeks] GOOGLE INTERVIEW QUESTION

2011-05-09 Thread hary rathor
bro no company will accept your program with goto statement .

-- 
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] GOOGLE INTERVIEW QUESTION

2011-05-09 Thread Anders Ma
 sometimes we need goto, goto is not so evil.

On Tue, May 10, 2011 at 2:49 AM, Manjeet Chayel
chayel.manj...@gmail.com wrote:
 Dont use goto... its not good to have it.

 On Mon, May 9, 2011 at 2:44 PM, Anders Ma xuejiao...@gmail.com wrote:

 #include stdio.h
 #include string.h

 int is_palindrome(char* string, int start, int end)
 {
        int i = start, j = end;

        while (start = end) {
                if (string[start++] != string[end--])
                        return 0;
        }

        /* print */
        printf([%d,%d] , i, j);
        while ( i = j)
                printf(%c, string[i++]);
        printf(\n);

        return 1;
 }

 int main(int argc, char** argv)
 {
        int i, j, k;
        int len;
        char *p;

        if (argc != 2) {
                printf(usage padin (string)\n);
                return 0;
        }
        p = argv[1];
 BEGIN:

        len = strlen(p);
        for (i = 0; i  len; i++) {
                for (j = i, k = len; j = k; k--)
                        if (is_palindrome(p, j, k)) {
                                p += k - j + 1;
                                goto BEGIN;
                        }
        }

        return 0;
 }

 anders@ubuntu:~/c$ ./palin helloworld
 [0,0] h
 [0,0] e
 [0,1] ll
 [0,2] owo
 [0,0] r
 [0,0] l
 [0,0] d
 anders@ubuntu:~/c$ ./palin madamamadam
 [0,10] madamamadam
 anders@ubuntu:~/c$



 On Fri, May 6, 2011 at 8:58 PM, sourabh jakhar sourabhjak...@gmail.com
 wrote:
 
 
  On Fri, May 6, 2011 at 4:23 PM, sourabh jakhar sourabhjak...@gmail.com
  wrote:
 
  You are given a large string. You need to cut the string into chunks
  such
  that each substring that you get is a palindrome. Remember that each 1
  length string is always a palindrome. You need to find the minimum
  number of
  cuts that you need to make such that each substring is a palindrome.
 
  --
  SOURABH JAKHAR,(CSE)(3 year)
  ROOM NO 167 ,
  TILAK,HOSTEL
  'MNNIT ALLAHABAD
 
  The Law of Win says, Let's not do it your way or my way; let's do it
  the
  best way.
 
  --
  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.
 
 
 
  --
  SOURABH JAKHAR,(CSE)(3 year)
  ROOM NO 167 ,
  TILAK,HOSTEL
  'MNNIT ALLAHABAD
 
  The Law of Win says, Let's not do it your way or my way; let's do it
  the
  best way.
 
  --
  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.
 



 --
 Regards
 Anders

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




 --
 Cheers!!
 Manjeet Chayel

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




-- 
Regards
Anders

-- 
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] GOOGLE INTERVIEW QUESTION

2011-05-09 Thread oldman
I agree with Anders Ma's point,but in my opinion, using goto is risky in a
import interview

On Tue, May 10, 2011 at 9:52 AM, Anders Ma xuejiao...@gmail.com wrote:

  sometimes we need goto, goto is not so evil.

 On Tue, May 10, 2011 at 2:49 AM, Manjeet Chayel
 chayel.manj...@gmail.com wrote:
  Dont use goto... its not good to have it.
 
  On Mon, May 9, 2011 at 2:44 PM, Anders Ma xuejiao...@gmail.com wrote:
 
  #include stdio.h
  #include string.h
 
  int is_palindrome(char* string, int start, int end)
  {
 int i = start, j = end;
 
 while (start = end) {
 if (string[start++] != string[end--])
 return 0;
 }
 
 /* print */
 printf([%d,%d] , i, j);
 while ( i = j)
 printf(%c, string[i++]);
 printf(\n);
 
 return 1;
  }
 
  int main(int argc, char** argv)
  {
 int i, j, k;
 int len;
 char *p;
 
 if (argc != 2) {
 printf(usage padin (string)\n);
 return 0;
 }
 p = argv[1];
  BEGIN:
 
 len = strlen(p);
 for (i = 0; i  len; i++) {
 for (j = i, k = len; j = k; k--)
 if (is_palindrome(p, j, k)) {
 p += k - j + 1;
 goto BEGIN;
 }
 }
 
 return 0;
  }
 
  anders@ubuntu:~/c$ ./palin helloworld
  [0,0] h
  [0,0] e
  [0,1] ll
  [0,2] owo
  [0,0] r
  [0,0] l
  [0,0] d
  anders@ubuntu:~/c$ ./palin madamamadam
  [0,10] madamamadam
  anders@ubuntu:~/c$
 
 
 
  On Fri, May 6, 2011 at 8:58 PM, sourabh jakhar sourabhjak...@gmail.com
 
  wrote:
  
  
   On Fri, May 6, 2011 at 4:23 PM, sourabh jakhar 
 sourabhjak...@gmail.com
   wrote:
  
   You are given a large string. You need to cut the string into chunks
   such
   that each substring that you get is a palindrome. Remember that each
 1
   length string is always a palindrome. You need to find the minimum
   number of
   cuts that you need to make such that each substring is a palindrome.
  
   --
   SOURABH JAKHAR,(CSE)(3 year)
   ROOM NO 167 ,
   TILAK,HOSTEL
   'MNNIT ALLAHABAD
  
   The Law of Win says, Let's not do it your way or my way; let's do it
   the
   best way.
  
   --
   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.
  
  
  
   --
   SOURABH JAKHAR,(CSE)(3 year)
   ROOM NO 167 ,
   TILAK,HOSTEL
   'MNNIT ALLAHABAD
  
   The Law of Win says, Let's not do it your way or my way; let's do it
   the
   best way.
  
   --
   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.
  
 
 
 
  --
  Regards
  Anders
 
  --
  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.
 
 
 
 
  --
  Cheers!!
  Manjeet Chayel
 
  --
  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.
 



 --
 Regards
 Anders

 --
 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] GOOGLE INTERVIEW QUESTION

2011-05-09 Thread Anders Ma
#include stdio.h
#include string.h

int is_palindrome(char* string, int start, int end)
{
int i = start, j = end;

while (start = end) {
if (string[start++] != string[end--])
return 0;
}

/* print */
printf([%d,%d] , i, j);
while ( i = j)
printf(%c, string[i++]);
printf(\n);

return 1;
}

int main(int argc, char** argv)
{
int i, j, k;
int len, rescan;
char demo[] = madamimadam;
char *p;

if (argc != 2) {
printf(usage padin (string)\n);
return 0;
}
p = argv[1];

do {
rescan = 0;
len = strlen(p);
for (i = 0; i  len  rescan == 0; i++) {
for (j = i, k = len; j = k; k--)
if (is_palindrome(p, j, k)) {
p += k - j + 1;
rescan = 1;
break;
}
}
} while (rescan);

return 0;
}
anders@ubuntu:~/c$ gcc palindrome.c -o palin
anders@ubuntu:~/c$ ./palin helloworld
[0,0] h
[0,0] e
[0,1] ll
[0,2] owo
[0,0] r
[0,0] l
[0,0] d
anders@ubuntu:~/c$ ./palin madamimadam
[0,10] madamimadam
anders@ubuntu:~/c$ ./palin andersma
[0,0] a
[0,0] n
[0,0] d
[0,0] e
[0,0] r
[0,0] s
[0,0] m
[0,0] a


On Tue, May 10, 2011 at 10:11 AM, oldman fenghaungyuyi...@gmail.com wrote:
 I agree with Anders Ma's point,but in my opinion, using goto is risky in a
 import interview

 On Tue, May 10, 2011 at 9:52 AM, Anders Ma xuejiao...@gmail.com wrote:

  sometimes we need goto, goto is not so evil.

 On Tue, May 10, 2011 at 2:49 AM, Manjeet Chayel
 chayel.manj...@gmail.com wrote:
  Dont use goto... its not good to have it.
 
  On Mon, May 9, 2011 at 2:44 PM, Anders Ma xuejiao...@gmail.com wrote:
 
  #include stdio.h
  #include string.h
 
  int is_palindrome(char* string, int start, int end)
  {
         int i = start, j = end;
 
         while (start = end) {
                 if (string[start++] != string[end--])
                         return 0;
         }
 
         /* print */
         printf([%d,%d] , i, j);
         while ( i = j)
                 printf(%c, string[i++]);
         printf(\n);
 
         return 1;
  }
 
  int main(int argc, char** argv)
  {
         int i, j, k;
         int len;
         char *p;
 
         if (argc != 2) {
                 printf(usage padin (string)\n);
                 return 0;
         }
         p = argv[1];
  BEGIN:
 
         len = strlen(p);
         for (i = 0; i  len; i++) {
                 for (j = i, k = len; j = k; k--)
                         if (is_palindrome(p, j, k)) {
                                 p += k - j + 1;
                                 goto BEGIN;
                         }
         }
 
         return 0;
  }
 
  anders@ubuntu:~/c$ ./palin helloworld
  [0,0] h
  [0,0] e
  [0,1] ll
  [0,2] owo
  [0,0] r
  [0,0] l
  [0,0] d
  anders@ubuntu:~/c$ ./palin madamamadam
  [0,10] madamamadam
  anders@ubuntu:~/c$
 
 
 
  On Fri, May 6, 2011 at 8:58 PM, sourabh jakhar
  sourabhjak...@gmail.com
  wrote:
  
  
   On Fri, May 6, 2011 at 4:23 PM, sourabh jakhar
   sourabhjak...@gmail.com
   wrote:
  
   You are given a large string. You need to cut the string into chunks
   such
   that each substring that you get is a palindrome. Remember that each
   1
   length string is always a palindrome. You need to find the minimum
   number of
   cuts that you need to make such that each substring is a palindrome.
  
   --
   SOURABH JAKHAR,(CSE)(3 year)
   ROOM NO 167 ,
   TILAK,HOSTEL
   'MNNIT ALLAHABAD
  
   The Law of Win says, Let's not do it your way or my way; let's do
   it
   the
   best way.
  
   --
   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.
  
  
  
   --
   SOURABH JAKHAR,(CSE)(3 year)
   ROOM NO 167 ,
   TILAK,HOSTEL
   'MNNIT ALLAHABAD
  
   The Law of Win says, Let's not do it your way or my way; let's do it
   the
   best way.
  
   --
   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.
  
 
 
 
  --
  Regards
  Anders
 
  --
  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] GOOGLE INTERVIEW QUESTION

2011-05-06 Thread sourabh jakhar
On Fri, May 6, 2011 at 4:23 PM, sourabh jakhar sourabhjak...@gmail.comwrote:

 You are given a large string. You need to cut the string into chunks such
 that each substring that you get is a palindrome. Remember that each 1
 length string is always a palindrome. You need to find the minimum number of
 cuts that you need to make such that each substring is a palindrome.
 http://www.careercup.com/question?id=8972527

 --
 SOURABH JAKHAR,(CSE)(3 year)
 ROOM NO 167 ,
 TILAK,HOSTEL
 'MNNIT ALLAHABAD

 The Law of Win says, Let's not do it your way or my way; let's do it the
 best way.

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




-- 
SOURABH JAKHAR,(CSE)(3 year)
ROOM NO 167 ,
TILAK,HOSTEL
'MNNIT ALLAHABAD

The Law of Win says, Let's not do it your way or my way; let's do it the
best way.

-- 
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] Google Interview Question

2011-01-05 Thread MAC
dangling pointers ?? maybe..  also corrupted heap


On Wed, Jan 5, 2011 at 4:46 PM, bittu shashank7andr...@gmail.com wrote:

 You are given a the source to a application which is crashing when
 run. After running it 10 times in a debugger, you find it never
 crashes in the same place. The application is single threaded, and
 uses only the C standard library. What programming errors could be
 causing this crash? How would you test each 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
thanks
--mac

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



Re: [algogeeks] Google Interview Question

2011-01-05 Thread juver++
Corrupted stack - buffer overflow.

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



Re: [algogeeks] Google Interview Question

2011-01-05 Thread Umer Farooq
There might be some error in calculating the value of some variable(s) which
might be used to retrieve elements in some arrays/maintaining stack/linked
list or any other data structure that uses the value of that variable to
retrieve information from memory.

Carefully checking the values of variables that are used to
allocate/deallocate or retrieve memory contents can be helpful.

On Wed, Jan 5, 2011 at 5:07 PM, juver++ avpostni...@gmail.com wrote:

 Corrupted stack - buffer overflow.

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Umer

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



Re: [algogeeks] Google Interview Question

2010-12-28 Thread Terence

@ pacific:
Also consider the choice of flipping the node itself.
And if an internal node cannot be flipped, it is still possible to flip 
its value, only the above choice is not taken into consideration..


On 2010-12-28 13:27, pacific pacific wrote:

here is my approach :

Starting from the root node ,
if root node need to have a 1 ...
if root is an and gate :
 flips  = minflips for left child to have value 1 + minflips for 
the right child to have value 1

else
 flips = minimum of ( minflips for left child to have value 1 , 
minflips for right child to have value 1)


For  a leaf node , return 0 if the leaf has the value needed else 
return INFINITY.Also if at any internal node if it is not possible 
return INFINITY.


On Tue, Dec 28, 2010 at 10:06 AM, Anand anandut2...@gmail.com 
mailto:anandut2...@gmail.com wrote:


@Terence.

Could please elaborate your answer. Bottom up level order
traversal helps to get the final root value but how to use it to
find minimum flips needed to Obtain the desired root value.




On Fri, Dec 24, 2010 at 1:56 AM, Terence technic@gmail.com
mailto:technic@gmail.com wrote:

Using the same level order traversal (bottom up), calculating
the minimum flips to turn each internal node to given value
(0/1).



On 2010-12-24 17:19, bittu wrote:


Boolean tree problem:

Each leaf node has a boolean value associated with it, 1
or 0. In
addition, each interior node has either an AND or an
OR gate
associated with it. The value of an AND gate node is
given by the
logical AND of its two children's values. The value of an
OR gate
likewise is given by the logical OR of its two children's
values. The
value of all of the leaf nodes will be given as input so
that the
value of all nodes can be calculated up the tree.
It's easy to find the actual value at the root using level
order
traversal and a stack(internal if used recursion).

Given V as the desired result i.e we want the value
calculated at the
root to be V(0 or 1) what is the minimum number of gates
flip i.e. AND
to OR or OR to AND be required at internal nodes to
achieve that?

Also for each internal node you have boolean associated
which tells
whether the node can be flipped or not. You are not
supposed to flip a
non flippable internal node.


Regards
Shashank Mani Narayan
BIT Mesra


-- 
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 mailto:algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
mailto:algogeeks%2bunsubscr...@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
mailto:algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
mailto:algogeeks%2bunsubscr...@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.


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



Re: [algogeeks] Google Interview Question

2010-12-27 Thread Anand
@Terence.

Could please elaborate your answer. Bottom up level order traversal helps to
get the final root value but how to use it to find minimum flips needed to
Obtain the desired root value.



On Fri, Dec 24, 2010 at 1:56 AM, Terence technic@gmail.com wrote:

 Using the same level order traversal (bottom up), calculating the minimum
 flips to turn each internal node to given value (0/1).



 On 2010-12-24 17:19, bittu wrote:


 Boolean tree problem:

 Each leaf node has a boolean value associated with it, 1 or 0. In
 addition, each interior node has either an AND or an OR gate
 associated with it. The value of an AND gate node is given by the
 logical AND of its two children's values. The value of an OR gate
 likewise is given by the logical OR of its two children's values. The
 value of all of the leaf nodes will be given as input so that the
 value of all nodes can be calculated up the tree.
 It's easy to find the actual value at the root using level order
 traversal and a stack(internal if used recursion).

 Given V as the desired result i.e we want the value calculated at the
 root to be V(0 or 1) what is the minimum number of gates flip i.e. AND
 to OR or OR to AND be required at internal nodes to achieve that?

 Also for each internal node you have boolean associated which tells
 whether the node can be flipped or not. You are not supposed to flip a
 non flippable internal node.


 Regards
 Shashank Mani Narayan
 BIT Mesra


 --
 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.comalgogeeks%2bunsubscr...@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.



Re: [algogeeks] Google Interview Question

2010-12-27 Thread pacific pacific
here is my approach :

Starting from the root node ,
if root node need to have a 1 ...
if root is an and gate :
 flips  = minflips for left child to have value 1 + minflips for the
right child to have value 1
else
 flips = minimum of ( minflips for left child to have value 1 , minflips
for right child to have value 1)

For  a leaf node , return 0 if the leaf has the value needed else return
INFINITY.Also if at any internal node if it is not possible return INFINITY.

On Tue, Dec 28, 2010 at 10:06 AM, Anand anandut2...@gmail.com wrote:

 @Terence.

 Could please elaborate your answer. Bottom up level order traversal helps
 to get the final root value but how to use it to find minimum flips needed
 to Obtain the desired root value.




 On Fri, Dec 24, 2010 at 1:56 AM, Terence technic@gmail.com wrote:

 Using the same level order traversal (bottom up), calculating the minimum
 flips to turn each internal node to given value (0/1).



 On 2010-12-24 17:19, bittu wrote:


 Boolean tree problem:

 Each leaf node has a boolean value associated with it, 1 or 0. In
 addition, each interior node has either an AND or an OR gate
 associated with it. The value of an AND gate node is given by the
 logical AND of its two children's values. The value of an OR gate
 likewise is given by the logical OR of its two children's values. The
 value of all of the leaf nodes will be given as input so that the
 value of all nodes can be calculated up the tree.
 It's easy to find the actual value at the root using level order
 traversal and a stack(internal if used recursion).

 Given V as the desired result i.e we want the value calculated at the
 root to be V(0 or 1) what is the minimum number of gates flip i.e. AND
 to OR or OR to AND be required at internal nodes to achieve that?

 Also for each internal node you have boolean associated which tells
 whether the node can be flipped or not. You are not supposed to flip a
 non flippable internal node.


 Regards
 Shashank Mani Narayan
 BIT Mesra


 --
 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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.



Re: [algogeeks] Google Interview Question

2010-12-24 Thread Terence
Using the same level order traversal (bottom up), calculating the 
minimum flips to turn each internal node to given value (0/1).



On 2010-12-24 17:19, bittu wrote:


Boolean tree problem:

Each leaf node has a boolean value associated with it, 1 or 0. In
addition, each interior node has either an AND or an OR gate
associated with it. The value of an AND gate node is given by the
logical AND of its two children's values. The value of an OR gate
likewise is given by the logical OR of its two children's values. The
value of all of the leaf nodes will be given as input so that the
value of all nodes can be calculated up the tree.
It's easy to find the actual value at the root using level order
traversal and a stack(internal if used recursion).

Given V as the desired result i.e we want the value calculated at the
root to be V(0 or 1) what is the minimum number of gates flip i.e. AND
to OR or OR to AND be required at internal nodes to achieve that?

Also for each internal node you have boolean associated which tells
whether the node can be flipped or not. You are not supposed to flip a
non flippable internal node.


Regards
Shashank Mani Narayan
BIT Mesra



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



Re: [algogeeks] Google interview question

2010-12-14 Thread sourabh jakhar
i have a one idea in my mind is to implement a hash table structure based on
26 alphabets
and a data structure of words.
struct word
{
int info;
char a[n];
};
structure  contains the info about the word and an array in  which document
it is present or not out of n
ex if it is word is mnnit and it is in document 1 ,4,6,9
the info of the structure would be char[1,4,6,9]=1
and the rest are zero.
insertion of word would take o(1) time but searching would take o(n) time if
list is implemented as an array list
and if implemented as an binary search tree would take it log(n) but than
insertion would also take log(n) time


On Mon, Dec 13, 2010 at 9:55 PM, GOBIND KUMAR gobind@gmail.com wrote:

 One of my friends attended google interview.This was one the question
 asked.

  you are given N documents(possibly in millions) with words in them.
 design datastructures such that the following scenarios take optimal time:

 a. print all the the docs having a given word

 b. print the docs having both of 2 given words


 Help me in solving this problem.

  --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
SOURABH JAKHAR,(CSE)(3 year)
ROOM NO 167 ,
TILAK,HOSTEL
'MNNIT ALLAHABAD

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



Re: [algogeeks] Google Interview Question

2010-09-14 Thread TurksHead Education
Number of correctly matched pair of n parenthesis will be a catalan number
Cn. You may want to see the application of catalan numbers at
http://www.rawkam.com/?p=568
http://www.rawkam.com/?p=568

On Tue, Sep 14, 2010 at 8:27 PM, bittu shashank7andr...@gmail.com wrote:

 Write a function Brackets(int n) that prints all combinations of well-
 formed brackets. For Brackets(3) the output would be ((())) (()()) (())
 () ()(()) ()()()



 with explaination dat is at every call what is contant of stack during
 pushing and popping

 --
 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.comalgogeeks%2bunsubscr...@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.



Re: [algogeeks] Google Interview Question

2010-07-15 Thread harit agarwal
@varun
c should also be in the array

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



Re: [algogeeks] Google Interview Question

2010-07-15 Thread umesh kewat
Hi,

suppose we have given n distinct numbers are a[n].

1. sort them using quick or any other sort in O(nlogn)
2. use then

 int find(int *arr, int n) /* return largest number if fing it otheriwse
retirn 0*/
 {
 int i,j,k, temp;

 for(k=n-1; k2;k--)
 {
j = k-1
i=0;
 while(i!=j)
  {
temp = arr[i]+arr[j];
if(temp== arr[k])
return arr[k];
else if(temparr[k])
i++;
else
j--;
   }
  }
 return 0;
}


-- 
Thanks  Regards

Umesh kewat
Hyderabad


On Thu, Jul 15, 2010 at 9:07 AM, Ashish Goel ashg...@gmail.com wrote:

 sort using counting sort or quickselect

 now a and b are less than c

 so find c first
 suppose c's index is k
 the start two indexes i=0 and j=k-1, if a[i]+a[j] ==a[k] return these
 numbers, else add elements at i,j if the sum is greater than c reduce j, if
 less than c increase i

 alternatively sort array, find index of c, make a BST or a hash table,
 starting from index 0 of the sorted array, find c-athis is overhead on
 second thoughts, i will proceed with first approach


 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652



 On Wed, Jul 14, 2010 at 9:55 PM, siddharth shankar 
 siddharth.shanka...@gmail.com wrote:

 O ( n^2 ) soln can be done 
 step :

 1 . sort array in n*log(n) .
 2.  for every C from last find two number A  B such that A+B=C ...   O(
 n^2 )
 Total :- O(N^2)

 can we improve it further ??  any help please 

 On Wed, Jul 14, 2010 at 10:57 AM, Debajyoti Sarma 
 sarma.debajy...@gmail.com wrote:

 An array contains the set of positive integer. Find the largest number
 c such that c=a+b where a,b,c are distinct number of the set?
 [Consider , reducing complexity]

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 siddharth shankar


  --
 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.comalgogeeks%2bunsubscr...@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.comalgogeeks%2bunsubscr...@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.



Re: [algogeeks] Google Interview Question

2010-07-14 Thread Varun Nagpal
First attempt: sort them and add the 2 largest numbers
2nd attempt: find 1st and 2nd largest number and add them.

On Wed, Jul 14, 2010 at 7:27 AM, Debajyoti Sarma
sarma.debajy...@gmail.comwrote:

 An array contains the set of positive integer. Find the largest number
 c such that c=a+b where a,b,c are distinct number of the set?
 [Consider , reducing complexity]

 --
 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.comalgogeeks%2bunsubscr...@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.



Re: [algogeeks] Google Interview Question

2010-07-14 Thread siddharth shankar
O ( n^2 ) soln can be done 
step :

1 . sort array in n*log(n) .
2.  for every C from last find two number A  B such that A+B=C ...   O(
n^2 )
Total :- O(N^2)

can we improve it further ??  any help please 

On Wed, Jul 14, 2010 at 10:57 AM, Debajyoti Sarma sarma.debajy...@gmail.com
 wrote:

 An array contains the set of positive integer. Find the largest number
 c such that c=a+b where a,b,c are distinct number of the set?
 [Consider , reducing complexity]

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
siddharth shankar

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



Re: [algogeeks] Google Interview Question

2010-07-14 Thread Ashish Goel
sort using counting sort or quickselect

now a and b are less than c

so find c first
suppose c's index is k
the start two indexes i=0 and j=k-1, if a[i]+a[j] ==a[k] return these
numbers, else add elements at i,j if the sum is greater than c reduce j, if
less than c increase i

alternatively sort array, find index of c, make a BST or a hash table,
starting from index 0 of the sorted array, find c-athis is overhead on
second thoughts, i will proceed with first approach


Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652


On Wed, Jul 14, 2010 at 9:55 PM, siddharth shankar 
siddharth.shanka...@gmail.com wrote:

 O ( n^2 ) soln can be done 
 step :

 1 . sort array in n*log(n) .
 2.  for every C from last find two number A  B such that A+B=C ...   O(
 n^2 )
 Total :- O(N^2)

 can we improve it further ??  any help please 

 On Wed, Jul 14, 2010 at 10:57 AM, Debajyoti Sarma 
 sarma.debajy...@gmail.com wrote:

 An array contains the set of positive integer. Find the largest number
 c such that c=a+b where a,b,c are distinct number of the set?
 [Consider , reducing complexity]

 --
 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.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 siddharth shankar


  --
 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.comalgogeeks%2bunsubscr...@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.