Re: [algogeeks] Find longest consecutive subsequence

2014-01-27 Thread Nishant Pandey
I think this the most optimized code i have writen :

#include iostream
#include vector
#include map
using namespace std;

int longest_sequence(vectorint nums) {
  mapint,bool mp;
  int count;
  int max = -;
  int n = 0;
  for(unsigned int i = 0; i  nums.size(); i++) {
mp[nums[i]] = true;
  }

  for(unsigned int i =0;inums.size();i++) {
n = nums[i];
mp.erase(n);
count = 1;
while(mp.find(n+1)!= mp.end()) {
  count++;
  mp.erase(n+1);
  n++;
}
n = nums[i];
while(mp.find(n-1)!= mp.end()) {
  count++;
  mp.erase(n-1);
  n--;
}
if(count  max) {
  max = count;
}
  }
  return max;
}

int main() {
// your code goes here
cout  Jai Ganesha;
vectorint vc;
vc.push_back(5);
vc.push_back(20);
vc.push_back(45);
vc.push_back(3);
vc.push_back(98);
vc.push_back(4);
vc.push_back(21);
vc.push_back(1);
vc.push_back(99);
vc.push_back(2);
cout  endl  longest_sequence(vc);
return 0;
}



NIshant Pandey
Cell : 9911258345
Voice Mail : +91 124 451 2130




On Mon, Jan 27, 2014 at 4:29 PM, Amol Sharma amolsharm...@gmail.com wrote:

 Given an array of positive numbers arranged in any order. You have to find
 the length of longest continuos(difference of +1, -1) sequence in the array.

 for eg.
 A[] = *5*, 20, 45, *3*, 98, *4*, 21, *1*, 99, *2*

 then longest continuos subsequence is [1, 2, 3, 4, 5] and hence the output
 should be *5*, the length of this sequence.

 Other Continuos sequence are -

 [20, 21]
 [45]
 [98, 99]
 [21]

 A[i] can be  10^6, so hashing is not an option.

 Possible Approach is by sorting and time complexity will be O(nlogn).

 Does anyone have better approach for this ?



 --
 Thanks and Regards,
 Amol Sharma

  --
 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] DISTINCT Permutations ( Not Easy)

2014-01-07 Thread Nishant Pandey
This will help u i guess :

#include iostream
#include string.h
using namespace std;

void swap(char str[],int m,int n ) {
char temp=str[m];
str[m]=str[n];
str[n]=temp;
}
bool duplicate(char str[], int start, int end)
{   if(start == end)
  return false;
else
  for(; startend; start++)
if (str[start] == str[end])
  return true;
  return false;
}
void Permute(char str[], int start, int end)
{
if(start = end){
  coutstrendl;
  return;
}
for(int i=start;i=end;i++)
{  if(!duplicate(str,start,i))
   {
swap(str,start,i);
Permute(str,start+1,end);
swap(str,start,i);
   }
}
}

int main()
{
  char Str[]=aba;
  Permute(Str,0,strlen(Str)-1);
   return 0;
}



NIshant Pandey
Cell : 9911258345
Voice Mail : +91 124 451 2130




On Tue, Jan 7, 2014 at 4:44 PM, kumar raja rajkumar.cs...@gmail.com wrote:

 This u can do it using the backtracking method. To know how to use
 backtracking refer algorithm design manual by steve skiena.


 On 7 January 2014 03:35, bujji jajala jajalabu...@gmail.com wrote:

 generate all possible DISTINCT permutations of a given string with some
 possible repeated characters. Use as minimal memory as possible.

 if given string contains n characters in total with m  n distinct
 characters each occuring n_1, n_2, n_m times where n_1 + n_2 + ...+ n_m
 = n

 program should generate n! / ( n_1! * n_2! * * n_m!  )  strings.

 Ex:
  aba  is given string

 Output:

 aab
 aba
 baa


 -Thanks,
 Bujji

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


-- 
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] How to read multiple utf-8 encoded string from stdin

2013-11-26 Thread Nishant Pandey
this way only helps in linux but when i use in windows with utf-8 encoded
input file for reading characters i cant do it , secondly how to count non
ascii characters from utf-8 string , any one is having any idea on this ?


On Mon, Nov 25, 2013 at 11:50 AM, Karthikeyan V.B kartmu...@gmail.comwrote:



   From StackOverflow,

 ---

 fgets() can decode UTF-8 encoded files if you use Visual Studio 2005 and
 up. Change your code like this:


 infile = fopen(inname, r, ccs=UTF-8);



 On Sat, Nov 23, 2013 at 8:25 PM, Nishant Pandey 
 nishant.bits.me...@gmail.com wrote:

 Q) *C program* that reads multiple UTF-8 encoded strings from STDIN (1
 string per line), count all *non-ascii* characters (ascii characters are
 with ordinal decimal 0 to 127) and print the total non-ascii character
 count to STDOUT (1 number per line).

 Contraint :


- You cannot use any *wchar.h* service in your program.
- The UTF-8 strings supplied to you can have *1 or more whitespaces* in
them.
- No input string will have a character length greater than*200 
 *(including
spaces)
- You will be given multiple lines of input (1 string per line).
- Input will be limited to UTF-8 encoded strings and will not contain
any garbage values.

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


-- 
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] How to read multiple utf-8 encoded string from stdin

2013-11-26 Thread Nishant Pandey
The Code is Awsome pradeep except few  things :
1) the output is coming wrong in 2 cases : a) x√ab c  counting non-ascii as
2 it should be 1
  b)ɖ  Ɛ
counting non-ascii as 4 it should be 2.


On Tue, Nov 26, 2013 at 7:57 PM, Pradeep Dubey pradeep.d...@gmail.comwrote:

 is this what you are asking:

 #includestdio.h
 #includestring.h

 /* MASK to check the numebr of BYTES character is using */
 #define ASCII_BYTE 0x80
 #define TWO_BYTE 0xC0
 #define THREE_BYTES 0xE0
 #define FOUR_BYTES 0xF0
 #define FIVE_BYTES 0xF8
 #define SIX_BYTES 0xFC

 #define MASK_BYTE 0xFF
 #define MAX_BUFF 200

 int non_ascii_count(char arr[]){
unsigned int  non_ascii = 0, count = 0,num=0;
char *ch = arr;
while (*ch != '\0') {
num = (unsigned int)(*ch) ;
 /* Only one last byte of the uint is required */
 num = num  MASK_BYTE;
 /* Check for multi-byte only if its not an ASCII, val  128 */
if (num  ASCII_BYTE ) {
 /* Is a Non ASCII */
 count = 0;
 if (num  TWO_BYTE) {
 count = 2;
 } else if (num  THREE_BYTES) {
 count = 3;
 } else if (num  FOUR_BYTES) {
 count = 4;
 } else if (num  FIVE_BYTES) {
 count = 5;
 } else if (num  SIX_BYTES) {
 count = 6;
 }
 /* Increment nonascii count and char pointer accordingly */
 non_ascii++;
 ch+=count;
 }
 /* ASCII , increment by one only */
ch++;
}
 return non_ascii;
 }

 int main(void)
 {
 FILE* fd = stdin;
 char buff[MAX_BUFF + 2]; /* 2 Extra for \0  \n */
 memset(buff,0,sizeof(buff));
 /* fgets reads max one less than provided length so adding 1 */
 while (NULL != fgets(buff,MAX_BUFF+1,fd))
 printf(%d\n, non_ascii_count(buff));
 return 0;
 }


 On Tue, Nov 26, 2013 at 7:43 PM, Nishant Pandey 
 nishant.bits.me...@gmail.com wrote:

 this way only helps in linux but when i use in windows with utf-8 encoded
 input file for reading characters i cant do it , secondly how to count non
 ascii characters from utf-8 string , any one is having any idea on this ?


 On Mon, Nov 25, 2013 at 11:50 AM, Karthikeyan V.B kartmu...@gmail.comwrote:



   From StackOverflow,

 ---

 fgets() can decode UTF-8 encoded files if you use Visual Studio 2005 and
 up. Change your code like this:


 infile = fopen(inname, r, ccs=UTF-8);



 On Sat, Nov 23, 2013 at 8:25 PM, Nishant Pandey 
 nishant.bits.me...@gmail.com wrote:

 Q) *C program* that reads multiple UTF-8 encoded strings from STDIN (1
 string per line), count all *non-ascii* characters (ascii characters
 are with ordinal decimal 0 to 127) and print the total non-ascii character
 count to STDOUT (1 number per line).

 Contraint :


- You cannot use any *wchar.h* service in your program.
- The UTF-8 strings supplied to you can have *1 or more whitespaces* in
them.
- No input string will have a character length greater than*200 
 *(including
spaces)
- You will be given multiple lines of input (1 string per line).
- Input will be limited to UTF-8 encoded strings and will not
contain any garbage values.

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


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




 --
 Regards,
 Pradeep

 --
 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] How to read multiple utf-8 encoded string from stdin

2013-11-25 Thread Nishant Pandey
How about counting non ASCII from it ... Checking mere ASCII doesn't help
as utf8 it self  is combination of characters ...
On Nov 25, 2013 11:50 AM, Karthikeyan V.B kartmu...@gmail.com wrote:



   From StackOverflow,

 ---

 fgets() can decode UTF-8 encoded files if you use Visual Studio 2005 and
 up. Change your code like this:


 infile = fopen(inname, r, ccs=UTF-8);



 On Sat, Nov 23, 2013 at 8:25 PM, Nishant Pandey 
 nishant.bits.me...@gmail.com wrote:

 Q) *C program* that reads multiple UTF-8 encoded strings from STDIN (1
 string per line), count all *non-ascii* characters (ascii characters are
 with ordinal decimal 0 to 127) and print the total non-ascii character
 count to STDOUT (1 number per line).

 Contraint :


- You cannot use any *wchar.h* service in your program.
- The UTF-8 strings supplied to you can have *1 or more whitespaces* in
them.
- No input string will have a character length greater than*200 
 *(including
spaces)
- You will be given multiple lines of input (1 string per line).
- Input will be limited to UTF-8 encoded strings and will not contain
any garbage values.

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


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


[algogeeks] How to read multiple utf-8 encoded string from stdin

2013-11-23 Thread Nishant Pandey
Q) *C program* that reads multiple UTF-8 encoded strings from STDIN (1
string per line), count all *non-ascii* characters (ascii characters are
with ordinal decimal 0 to 127) and print the total non-ascii character
count to STDOUT (1 number per line).

Contraint :


   - You cannot use any *wchar.h* service in your program.
   - The UTF-8 strings supplied to you can have *1 or more whitespaces* in
   them.
   - No input string will have a character length greater than*200 *(including
   spaces)
   - You will be given multiple lines of input (1 string per line).
   - Input will be limited to UTF-8 encoded strings and will not contain
   any garbage values.

-- 
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] Re: Intrestting problem

2013-06-12 Thread Nishant Pandey
juat want to ask why the last region was not flipped from o to x?


On Tue, Jun 11, 2013 at 11:57 PM, Don dondod...@gmail.com wrote:

 // Flip a region including location (x,y) from from to to.
 // Returns true if region is surrounded.
 bool flip(char board[][], int n, int x, int y, char from, char to)
 {
if ((x = 0)  (y = 0)  (x  n)  (y  n)) return false;
if (board[x][y] != from) return true;
board[x][y] = to;
return flip(board,n,x-1,y)  flip(board,n,x+1,y) 
 flip(board,n,x,y-1)  flip(board,n,x,y+1);
 }

 // Flips all regions of 'O' completely surrounded by 'X' to 'X'
 void captureSurrounded(char board[][], int n, int x, int y)
 {
 int x,y;
 for(x = 0; x  n; ++x)
for(y = 0; y  n; ++y)
if (flip(board,n,x,y,'O','v'))
flip(board,n,x,y, 'v', 'X');

 // Set regions not surrounded back to 'O'
 for(x = 0; x  n; ++x)
for(y = 0; y  n; ++y)
if (board[x][y] == 'v') board[x][y] = 'O';
 }

 On Jun 11, 3:05 am, Jai Shri Ram del7...@gmail.com wrote:
  Given a 2D board containing 'X' and 'O', capture all regions surrounded
 by
  'X'.
 
  A region is captured by flipping all 'O's into 'X's in that surrounded
  region .
 
  For example,
 
  X X X X
  X O O X
  X X O X
  X O X X
 
  After running your function, the board should be:
 
  X X X X
  X X X X
  X X X X
  X O X X

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




[algogeeks] circumference of a tree going clockwise and anticlockwise?

2013-06-01 Thread Nishant Pandey
does that means displaying only boundary elements of tree and if yes in
which order ?

*My Answer* :

I think it would be something like doing preorder travesal of left subree
with boundary elements and leaf elements of left subtree + post order
traversal of right subtree with boundary element and leaf node.

If its otherwise, please let me know.

-- 
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] How will you implement a stack using a priority queue. Push and pop should be in O(1)

2013-05-26 Thread Nishant Pandey
@Ankur... what ever we are inserting we are inserting at the head of the
list, so its O(1).
we are overriding Enque method with Push().


On Sun, May 26, 2013 at 10:15 AM, Ankur Khurana ankur.kkhur...@gmail.comwrote:

 but in this approach , How is Push having O(1)  complexity ?


 On 25 May 2013 17:52, rohit jangid rohit.nsi...@gmail.com wrote:

 you are doing it correct.


 On Sat, May 25, 2013 at 5:37 PM, Nishant Pandey 
 nishant.bits.me...@gmail.com wrote:

 I am not getting the y priority Q is getting used for this question, as
 in case of P Queue, things are arranged as per the priority so when we will
 insert the data we can simply increament the priority.

 Algo would be like this :

 Enque(q, data) {
   push(q, data, increrase the prioroty);
 }

 int Deque() {
 return pop();
 }

 here higher priority  one shuld be poped first.

 PLEASE SUGGEST if any good approach some one is having other than this ?


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






 --
 Rohit Jangid
 http://rohitjangid.com
 Graduate
 Deptt. of Computer Engineering
 NSIT, Delhi University, India

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






 --
 Regards,
 Ankur Khurana
 Software Developer Engineer,
 Microsoft India Development Center,
 Hyderabad.

  --
 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] What data structures will you use to implement a text editor. Size of editor can be changed and you also need to save the styling information for all the text like italic, bold etc.EO

2013-05-26 Thread Nishant Pandey
i feel stack would be good as we undo the last edited item easily in stack,
i have not implemented Rope, if some have implemented Rope, please help me
i am interested in implementing Rope.


On Sun, May 26, 2013 at 4:21 PM, Nitish Raj raj.n...@gmail.com wrote:

 Ravi you r correct. Rope aka Cord.


 On Sun, May 26, 2013 at 9:36 AM, Ravi Ranjan ravi.cool2...@gmail.comwrote:

 Rope


 On Sat, May 25, 2013 at 10:24 PM, Nishant Pandey 
 nishant.bits.me...@gmail.com wrote:

 In one of the interview it was asked, can some one suggest good DS for
 this.

 Thanks

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




  --
 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] inplace merge of 2 sorted parts of an array

2013-05-26 Thread Nishant Pandey
The solution could be given in this way.

1) In one pass get the end index of both array says e1 and e2.
2) now in next pass compare elements at e1 and e2 .
   a) if a(e1)  a(e2) swap the elements and then decreament e1 and e2 both.
   b) if a(e1)  a(e2) decreament e2.
   c) if a(e1) == a(e2) then swap a(e1) with a(e2-1) and then decrement e1
by1 and e2 by 2.

After this pass there may be one or two element not at coret position, so
their position can be placed just by shifting in elements in another pass.

So as a total it would be O(n) but it requires 3 passes.


If some one is having something better tan this, please suggest.



On Sun, May 26, 2013 at 6:46 PM, bharat b bagana.bharatku...@gmail.comwrote:

 An array is given, first and second half are sorted .. Make the array
 sorted inplace... Need an algo better than O(n^2)..
 If the length of the array is odd.. middle is either in first half or
 second half.
 Ex:
 1. Arr[] = {2,3,6,8,-5,-2,3,8} -- output : Arr[]={-5,-2,2,3,3,6,8,8};
 2. Arr[] = {2,3,6,8,-5,-2,3} --  output : Arr[]={-5,-2,2,3,3,6,8};
 3. Arr[] ={2,3,6,-5,-2,3,8} --  output : Arr[]={-5,-2,2,3,3,6,8};

  --
 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] Re: count number of set bits in an (big) array (Asked in Google interview)

2013-05-26 Thread Nishant Pandey
@DOn can u explain ur first algo, it would be helpful.


On Wed, May 22, 2013 at 7:28 PM, Don dondod...@gmail.com wrote:

 My program works with any numbers.
 Don

 On May 22, 3:45 am, Pramida Tumma pramida.tu...@gmail.com wrote:
  This above program works only if the array contains consecutive numbers
  starting from 1 to n. What to do if the array contains random numbers?
 
 
 
 
 
 
 
  On Fri, May 17, 2013 at 6:55 PM, Don dondod...@gmail.com wrote:
   Counting the set bits in one integer is not the problem which was
   asked.
   However, I think that something like this is both faster and more easy
   to understand than what you have written:
 
   int bitCount(unsigned int x)
   {
  int result = 0;
  while(x)
  {
 if (x  1) ++result;
 x = 1;
  }
  return result;
   }
 
   On May 17, 8:32 am, bhargav ybbkris...@gmail.com wrote:
as bitwise operators are fast can count by following logic, works
 oly fr
+ve, just a tweak will make it to work with -ves also ..
 
#include stdio.h
main() {
unsigned int x=12312,a;
a=x1;
//printf(%u,a);
int count=0;
while(x0) {
a = x1;
//printf(%u \n,a);
if(ax)
count++;
x=a;}
 
printf(%d\n,count );
getch();
 
}
 
   --
   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.




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




[algogeeks] How will you implement a stack using a priority queue. Push and pop should be in O(1)

2013-05-25 Thread Nishant Pandey
I am not getting the y priority Q is getting used for this question, as in
case of P Queue, things are arranged as per the priority so when we will
insert the data we can simply increament the priority.

Algo would be like this :

Enque(q, data) {
  push(q, data, increrase the prioroty);
}

int Deque() {
return pop();
}

here higher priority  one shuld be poped first.

PLEASE SUGGEST if any good approach some one is having other than this ?

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




[algogeeks] What data structures will you use to implement a text editor. Size of editor can be changed and you also need to save the styling information for all the text like italic, bold etc.EOM

2013-05-25 Thread Nishant Pandey
In one of the interview it was asked, can some one suggest good DS for this.

Thanks

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




[algogeeks] PLease suggest the Algo for this problem

2013-05-23 Thread Nishant Pandey
I have a list of N teams T1, T2, T3 … Tn. Each of these teams has played a
match against every other team. I have a function displayResult(Team T1,
Team T2), it returns the team which won the match between any two given
teams T1 and T2.
I have to write the teams in an order such the (n-1)th team (in the order)
had lost to the nth team which in turn had lost to (n+1)th team.

I want optimize code for this, please help.

-- 
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] Re: PLease suggest the Algo for this problem

2013-05-23 Thread Nishant Pandey
@DON,

For example if in a particular order, the teams appeared as T1, T2, T3, T4
… then team T1 had lost to T2, T2 had lost to T3, and T3 had lost to T4… It
may be possible that T3 lost to T1 .. but that need not be taken into
consideration while writing the order. Only the neighboring elements should
be such that the element on the left has lost to the element on the right.


On Thu, May 23, 2013 at 8:47 PM, Don dondod...@gmail.com wrote:

 This is not necessarily possible.

 If you have teams A, B, and C, it is possible that
 A beat B
 B beat C
 C beat A.

 Based on the first two games the ranking should be A,B,C. But based on
 the third game, C should be ranked higher than A.

 Don

 On May 23, 11:06 am, Nishant Pandey nishant.bits.me...@gmail.com
 wrote:
  I have a list of N teams T1, T2, T3 … Tn. Each of these teams has played
 a
  match against every other team. I have a function displayResult(Team T1,
  Team T2), it returns the team which won the match between any two given
  teams T1 and T2.
  I have to write the teams in an order such the (n-1)th team (in the
 order)
  had lost to the nth team which in turn had lost to (n+1)th team.
 
  I want optimize code for this, please help.

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




[algogeeks] Rope Data Structure Implementation

2013-05-17 Thread Nishant Pandey
I want to implement rope data stucture from scratch in c , is there any
good material that can help me implement this with ease.

Thanks
Nishant

-- 
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] Re: Print a Random word from a file. Input is path to a file, constraints- No extra memory like hashing etc. All the words in the file should have equal probability.

2013-05-12 Thread Nishant Pandey
i am little confused with the solution, like if i say there are duplicate
words,  will this algo produce the words with equal
probability?


On Mon, May 6, 2013 at 7:59 PM, Dave dave_and_da...@juno.com wrote:

 Oops. The statement  int I = 1 in the above should be  int k = 1. Sorry.

 Dave

 On Sunday, May 5, 2013 9:10:37 PM UTC-5, Dave wrote:

 @Nishant: I'm assuming that you don't know the number of words in the
 file, and that you don't want to store them all. Here is an algorithm that
 requires you to store only two words and an integer.
 Assume double function random() returns a uniformly distributed random
 number = 0.0 and  1.0.

 int i = 1
 read first word from file into string save;
 while not EOF
 {
 read next word from file into string temp;
 k++;
 if( k * random()  1.0 )
 copy temp to save; // happens with probability 1/k
 }
 print save;
 Here is why this works. The k-th word is initially selected with
 probability 1/k. It is replaced with the k+1st word with probability
 1/(k+1). Thus, the k-th word is not replaced with the k+1st word with
 probability 1 - 1/(k+1) = k/(k+1). Similarly, it is not replaced with the
 k+2nd word with probability (k+1)/(k+2). Etc. This means that the k-th word
 was selected and survives to the EOF with probability

 1/k * k/(k+1) * (k+1)/(k+2) * ... * (n-1)/n, where n is the number of
 words in the file.

 Every numerator equals the preceding denominator, so the product
 collapses to 1/n. This is true for any k with 1 = k = n, proving that the
 algorithm produces the desired result.

 Dave

 On Sunday, May 5, 2013 7:44:01 AM UTC-5, Nishant Pandey wrote:

 Hi Guys,

 In this problem i am wondering how it will be done without extra memory
 space, though we can easily do it with hashing and random funcs().
 Is there any solution for this , Please help.

  --
 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] Array of intergers with repeating elements

2013-05-12 Thread Nishant Pandey
i think u should utilize the property of XOR, this would help.


On Wed, May 8, 2013 at 12:02 AM, MAC macatad...@gmail.com wrote:


 I was asked this in recent amazon onsite interview and asked o write code

 Given an Array of integers . N elements occur k times and one element
 occurs b times, in other words there are n+1 distinct Elements. Given
 that 0  b  k find the element occurring b times.

 We know k is NOT even .


 thanks
 --mac

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




[algogeeks] I am new to CPP STL please help

2013-05-12 Thread Nishant Pandey
This is my code snippet
#include iostream.h
#include string
#include set
#include map
#include vector
#include sstream
#include cctype
using namespace std;

void work() {
mapstring, int name_age;
mapint,string index_name;
mapint,string index_name_temp;
std::map int, string ::iterator it;

name_age[abc] = 12;
name_age[pqr] = 1;
name_age[stu] = 13;

index_name[0] = abc;
index_name[1] = pqr;
index_name[2] = stu;

cout  name_age[abc]  endl;
cout  index_name[1];
name_age.erase(abc);

index_name_temp[0] = abc';

for ( it = index_name.begin(); it != index_name.end(); ++it )
{
  cout (*it).second   ;
}

In this i have deleted key abc first from hash table name_age in the next
hash table index_namei have abc as value i want to erase the abc entry
from index_name table too,
The idea is to first iterate on hash_map index_name when found abc delete
the entry from index_name but how to compare abc in index_name map.

as we cant do if (strcmp((*it).second, abc) ==0 ) in this , how do i do
the comparision please help


}

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




[algogeeks] Print a Random word from a file. Input is path to a file, constraints- No extra memory like hashing etc. All the words in the file should have equal probability.

2013-05-05 Thread Nishant Pandey
Hi Guys,

In this problem i am wondering how it will be done without extra memory
space, though we can easily do it with hashing and random funcs().
Is there any solution for this , Please help.

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




[algogeeks] For a given set of points find a point along with 3 others that are closest to each other

2013-05-03 Thread Nishant Pandey
Guys i am looking for optimize algorithm for this, please help.

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Interview Question

2013-04-26 Thread Nishant Pandey
the code is simply utilizing the xor property as u know xor sets on odd one
so, if any array would have numbers odd times repeated
their bit will only stay in xor operation else will get nulify.

so in first loop bit of 1 and 3 are set,  to seperate them we need to
divide them using any of their set bits and after that in second loop
we are xoring only odd ones whose bits are set and we get our ans in
variable x and y.

Hope u got it .


On Fri, Apr 19, 2013 at 11:30 PM, kartik n kartik.car...@gmail.com wrote:

 Hi Nishant i did not understand the code can u please describe a bit

 Thanks


 On Fri, Apr 19, 2013 at 10:48 AM, rahul sharma rahul23111...@gmail.comwrote:

 search the previous posts before posting

 search for
 [algogeeks] Amazon Interview Question
 you will get this

 --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




  --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Interview Question

2013-04-19 Thread Nishant Pandey
int main() {

int a[] = {1,2,2,3,3,3,4,4};

int size = sizeof(a)/sizeof(a[0]);
int xorr=0;
for(int i=0;isize;i++) {
xorr^=a[i];
}

int x=0,y=0;

int xor1=xorr  ~(xorr-1);

for(int i=0;isize;i++) {
 if(xor1  a[i]) x^=a[i];
 else y^=a[i];
}

cout xy;

}

in this 1 and 3 would be output. as it would be print the number repeated
odd times. so ur answer would be in y ie 3 .

If there issue with the code let me knw.


On Fri, Apr 19, 2013 at 10:52 AM, Krishnan aariyankrish...@gmail.comwrote:

 In an array, some numbers occur only once, some numbers occur twice, only
 one number occur thrice. Find the number occuring thrice ? Space complexity
 O(1) Time Complexity O(n). We should not use Hash Maps.

 Please someone help..


  --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Leaf nodes from inorder traversal

2013-03-17 Thread Nishant Pandey
what the issue with this , while doing inorder traversal check if left and
right both are null its ur leaf node else keep traversing.
If i couldn't understood ur problem , please explain again.


On Sat, Mar 16, 2013 at 7:44 PM, Megha Agrawal megha1...@iiitd.ac.inwrote:

 Hello all,

 Is it possible to get leaf nodes from inorder traversal of a binary
 tree(not BST)?

 --
 Thank you

   --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Amazon Interview Questions

2013-03-12 Thread Nishant Pandey
Ans to *Boundary traversal of a tree. Write the code.

*1) you need to for preoder oder for left most tree with flag and post
order traversal for right most tree with flag.
2) the role of flag would be to decide wther to print or not like in case
of left subtree ,flag would be tree as u knw that
in preorder traversal left element would be boundary and once u go
right make it false .. same for right subtree:

Code snippet would look like this :

void printleft (struct node *root, bool flag) {
  if (!root) return;
  if (flag || (!root-left  !root-right)) {
cout root-data;
  }
  printleft(root-left, true);
  printleft(root-right, false);
}

this is preorder for left subtree , do post order for right subtree like :

void printright (struct node *root, bool flag) {
  if (!root) return;
  printright(root-left, false);
  printright(root-right, true);
  if (flag || (!root-left  !root-right)) cout root-data;

}
*
*let me knw if anything seems confusing.
On Sun, Mar 10, 2013 at 4:59 PM, Nishant Pandey 
nishant.bits.me...@gmail.com wrote:

 i have few questions regarding ur problems pratik :

 1) A tree with only parent pointer, how to find LCA?
 Doubt : do u mean only root of the tree is given , i am assuming root
 along with two nodes address whose lca need to
  find too is given , i am right ?

 2) Find top k searched elements from a continuous stream of data.
 Doubt : what do u mean by top k search element can u please explain
 little bit with exmple.


 I would love to post solution for you provided clear my doubts 
 may i knw which Amazon's round questions are they ?


 On Mon, Feb 18, 2013 at 1:28 AM, Tushar tushicom...@gmail.com wrote:

 It looks as if you have just pasted some Amazon interview questions on
 this forum.
 These are pretty common questions.
 Try to come up with your own answers.
 Do some research on google and previous posts on this forum. You'll get
 answers to all of them.

 If you have some idea and want to discuss that, then post different posts
 for each questions as arun recommended along with your understanding of the
 question and your approach.

 All the best


 On Saturday, 9 February 2013 14:45:35 UTC+5:30, Pratik Mehta wrote:

 Hi All,
 I need ur help in solving few questions.

 Would you please help me out *BY GIVING THE ALGORITHM AND THE LOGIC
 BEHIND IT and it's DEEP EXPLANATION IF POSSIBLE?*


 *
 *

  *a. Kadane’s Algo.*

  *
 *

 *b. Linked-list intersection point.*

 *
 [A tree with only parent pointer, how to find LCA?]
 *

 *

 *

 *
 c. Design a stack which can perform findMax in O(1).
 *

 *

 *

 *d. Set of stocks for each day have been given. Need to find the days
 on which I buy and sell share to earn max profit, alongwith finding the max
 profit.*


 *
 e. Find top k searched elements from a continuous stream of data.
 *

 *

 *

 *f. Given a linked-list and 2 integers k  m. Reverse the linked-list
 till k elements and then traverse till m elements and repeat.*

 *Write production quality code.*

 *
 *

 *g. An array of elements have been given. Find for each element, first
 max element to its right.*

 *
 *

 *h. Boundary traversal of a tree. Write the code.*


 Please help me out...

 Thanks in advance...

 Thanks  Regards,
 Pratik Mayur Mehta.

  --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.






-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: Amazon Interview Questions

2013-03-12 Thread Nishant Pandey
i have few questions regarding ur problems pratik :

1) A tree with only parent pointer, how to find LCA?
Doubt : do u mean only root of the tree is given , i am assuming root along
with two nodes address whose lca need to
 find too is given , i am right ?

2) Find top k searched elements from a continuous stream of data.
Doubt : what do u mean by top k search element can u please explain
little bit with exmple.


I would love to post solution for you provided clear my doubts 
may i knw which Amazon's round questions are they ?

On Mon, Feb 18, 2013 at 1:28 AM, Tushar tushicom...@gmail.com wrote:

 It looks as if you have just pasted some Amazon interview questions on
 this forum.
 These are pretty common questions.
 Try to come up with your own answers.
 Do some research on google and previous posts on this forum. You'll get
 answers to all of them.

 If you have some idea and want to discuss that, then post different posts
 for each questions as arun recommended along with your understanding of the
 question and your approach.

 All the best


 On Saturday, 9 February 2013 14:45:35 UTC+5:30, Pratik Mehta wrote:

 Hi All,
 I need ur help in solving few questions.

 Would you please help me out *BY GIVING THE ALGORITHM AND THE LOGIC
 BEHIND IT and it's DEEP EXPLANATION IF POSSIBLE?*


 *
 *

 *a. Kadane’s Algo.*

 *
 *

 *b. Linked-list intersection point.*

 *
 [A tree with only parent pointer, how to find LCA?]
 *

 *

 *

 *
 c. Design a stack which can perform findMax in O(1).
 *

 *

 *

 *d. Set of stocks for each day have been given. Need to find the days on
 which I buy and sell share to earn max profit, alongwith finding the max
 profit.*


 *
 e. Find top k searched elements from a continuous stream of data.
 *

 *

 *

 *f. Given a linked-list and 2 integers k  m. Reverse the linked-list
 till k elements and then traverse till m elements and repeat.*

 *Write production quality code.*

 *
 *

 *g. An array of elements have been given. Find for each element, first
 max element to its right.*

 *
 *

 *h. Boundary traversal of a tree. Write the code.*


 Please help me out...

 Thanks in advance...

 Thanks  Regards,
 Pratik Mayur Mehta.

  --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] find out all pairs of numbers a,b such that a^2+b^2 = N

2013-03-12 Thread Nishant Pandey
some thing like would work.


int find(int x ) {
int p = sqrt(x/2);
int total=0;
float y;
for( int i=0;i=p;i++) {
  y=sqrt(x*x-i*i);
  if( y(int) == y) total++;
}
return total;

}



find(
}

On Thu, Feb 14, 2013 at 10:22 AM, Shachindra A C sachindr...@gmail.comwrote:

 Guneesh,

 Thanks for the reply.
 I interpret ur answer as follows:

 If N = say, 50

 the two combinations are (1,7) and (5,5).

 Acc to you, first find sqrt(50) = 7

 fill in 1,4,9,16,25,36,49 in an array.

 Then have min = 0, max = 6 and get all combinations in one pass over the
 array, right?

 So, the complexity would be O(n^0.5), right?

 Can you think of any solution making use of complex domain? Just curious
 to know...

 On Wed, Feb 13, 2013 at 10:28 PM, Guneesh Paul Singh 
 gunees...@gmail.comwrote:

 Replace all elements of array by its square.and sort it
 Now question is to find two  nos in the array such that their sum is N.
 For this take two pointers min and max
 Initialize min to 0 and max to n-1(n-size of array)
 1.find the sum a[min]+a[max]
 2.if sumN max=max-1
 if sumN min=min+1
 if sum==N we have a sol

 Now in case of nonunique values all possible pairs must be displayed
 eg for 2 2 3 3 N =5
 min=0,max 3 is a sol but u need to display all combination of 2 and 3 for
 that i used tempmin=position till which we have a value a[min] and temp max
 postion till which we have a value a[max] and display
 all possible combinations.

 P.S. This was asked to me in Amazon

 --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.






 --
 Regards,
 Shachindra A C

 --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Re: FInd unique element.

2013-03-12 Thread Nishant Pandey
i think what aditya suggested is cool but in that instead of going for
largest element we need to search smallest value and its index would he
number we are looking for.

On Sun, Feb 24, 2013 at 7:45 PM, Dave dave_and_da...@juno.com wrote:

 @Marti: If you know m and k, and if m is even and k is odd, then xoring
 the elements of the array will give the integer that occurs k times. But
 this is not a general algorithm for arbitrary m and k.

 Dave

 On Sunday, February 24, 2013 1:24:23 AM UTC-6, marti wrote:

 A hint is to use XOR for linear time..but how?

 On Friday, February 22, 2013 12:58:07 AM UTC+5:30, marti wrote:

 How do I Find the Unique Element that Appears exactly k Times in an
 Array?
  the problem is given an integer array, only one integer appears* k* times,
 all the other integers appears *m* times in the array (*k**m*). Find
 out that integer.

  --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Number of paths

2013-02-21 Thread Nishant Pandey
+1 for above approach , its called memotization .. it helps reducing
redundant recursive call for the same matter.

On Thu, Feb 21, 2013 at 2:29 PM, Karthikeyan V.B kartmu...@gmail.comwrote:

 Assuming that u can either move down or right,

 Using Dynamic Programming,

 a DP equation can be framed like this : Paths[i][j] = paths[i][j-1] +
 paths[i-1][j]
 By filling the entire matrix, result will be in Paths[m-1][n-1].

 --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Amazon interview Question

2013-02-07 Thread Nishant Pandey
what would happen of the input is like this : 5, 5, 66, 66, 7, 1, 1, 77,7
i think in this case the moment window reaches to point (66,7,1) it will
take 7 as unique number but
that too window will not move any futhur , but 7 is not unique .

Please comment if i misunderstood ur explanation .






On Wed, Feb 6, 2013 at 11:31 PM, Srikar srikar2...@gmail.com wrote:

 *APPROACH 1:*
 use a hashtable for both the questions ?

 Insert the integers as they are given in the array into a hashtable. The
 structure I am thinking is key (the integer) - [index]. Once all elements
 are inserted. Run through the hashtable and select the one which has
 len(value) == 1 and is least, since we want the first unique integer.

 for the second Q, its a more general Q of the first one. In first k=1.

 space: 2O(n)
 time: 2O(n)

 *APPROACH2: *
 When we say unique, we will have a pattern. Eg: [5, 5, 66, 66, 7, 1, 1,
 77]. In this lets have moving window of 3. first consider (5,5,66). we can
 easily estab. that there is duplicate here. So move the window by 1 element
 so we get (5,66,66). Same here. move to next (66,66,7). Again dups here.
 next (66,7,1). No dups here! take the middle element as this has to be the
 first unique in the set. The left element belongs to the dup so could 1.
 Hence 7 is the first unique element.

 space: O(1)
 time: O(n)

 For seond Q I still think hashtable is best. As the numbers are streamed,
 keep inserting.


 Srikar



 On Wed, Feb 6, 2013 at 10:00 AM, navneet singh gaur 
 navneet.singhg...@gmail.com wrote:

 nice algo ankit, so it will be nlogn using O (n) space only. What abt
 2nd Q., which have a big online stream.

 On Mon, Feb 4, 2013 at 9:30 PM, kumar ankit k.anki...@gmail.com wrote:
  For 1:
  i think you can use sorting, sort the array and keep the indices of the
  numbers in the sorted list.
  Now traverse the sorted list and  in the sorted list you need to find
 the
  unique number with the
  minimum index which is easy to find.
 
  Eg: Array:5 3 1 2 4 1 4
Indices: 0 1 2 3 4 5 6
 
 
  After sorting : Array:1 1 2 3 4 4 5
  Indices:  2 5 3 1 4 6 1
 
  Now you can see the unique number with lowest index is 3(index=1). So ,
 you
  have your answer.
 
 
  On Mon, Feb 4, 2013 at 3:45 PM, navneet singh gaur
  navneet.singhg...@gmail.com wrote:
 
  1. Given a array,find a first unique integer.
  2. Integers are coming as online stream,have to find a kth unique
 integer
  till now.
 
  For 1.
 
  Even we cannot use sorting for solving this as if we sort it than our
  first number which is non-repetitive changes.
 
  The best I am able to do is nlogn using a space of O( n ).
 
  For 2. No idea
 
  --
  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.
  For more options, visit https://groups.google.com/groups/opt_out.
 
 
 
 
 
 
  --
  Kumar Ankit
  Senior Undergraduate
  Department of Computer Engineering
  Institute of Technology
  Banaras Hindu University
  Varanasi
  Ph: +91 9473629892
 
  --
  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.
  For more options, visit https://groups.google.com/groups/opt_out.
 
 



 --
 navneet singh gaur

 --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.



  --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] size of array

2013-01-30 Thread Nishant Pandey
i already said this is not possible , in my intial draft , as we dont have
any information of memory owner in called function , just have base address
which is address of single element of the array .


On Wed, Jan 30, 2013 at 1:55 PM, Prem Krishna Chettri hprem...@gmail.comwrote:

 @Piyush .. Never works..

   @All  there is no way to do the given requirement in pure C.


 On Wed, Jan 30, 2013 at 1:45 PM, Piyush piyush.to...@gmail.com wrote:

  sizeof(array)/sizeof(array[0])


 On 28-Jan-13 3:44 PM, Anil Sharma wrote:

  How to calculate the size/lenght of an int array which is passed as an
 ONLY argument to a function??? --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




  --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




  --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] size of array

2013-01-29 Thread Nishant Pandey
i think this is not possible as you are passing only base address of the
int array to it , there is not information about the owner .

On Mon, Jan 28, 2013 at 3:44 PM, Anil Sharma anilsharmau...@gmail.comwrote:

 How to calculate the size/lenght of an int array which is passed as an
 ONLY argument to a function???

 --
 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.
 For more options, visit https://groups.google.com/groups/opt_out.




-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [algogeeks] Suggested the Data Structure to implement the solution in O(1)

2013-01-08 Thread Nishant Pandey
no i am using C for this implementation , can you suggest me algo for this

On Tue, Jan 8, 2013 at 5:55 PM, Sachin Maheshwari 
sachin.maheshw...@gmail.com wrote:

 If you are using Java, you can go with LinkedHashMap.




 On Sat, Jan 5, 2013 at 6:40 PM, Nishant Pandey 
 nishant.bits.me...@gmail.com wrote:

 Give a Data structure to store Name-value pair like name-age
 abc,12
 xyz,34...
 such than insert(name,value), value = search(name), name = nthentry(n),
 delete(name); all can be perfomed in O(1).
 Note:- after deletion order should be maintained.Ex.
 ds,12
 df,78
 teu,54
 etr,12
 If delete(df) is called then nthentry(2) should return teu


 Please suggest the solution ..

 --






 --
 Regards,
 Sachin Maheshwari
 Cell phone: +91.7259917298

 If we admit that human life can be ruled by reason; the possibility of
 life is destroyed. - Alexander Supertramp

 --




-- 




[algogeeks] Suggested the Data Structure to implement the solution in O(1)

2013-01-07 Thread Nishant Pandey
Give a Data structure to store Name-value pair like name-age
abc,12
xyz,34...
such than insert(name,value), value = search(name), name = nthentry(n),
delete(name); all can be perfomed in O(1).
Note:- after deletion order should be maintained.Ex.
ds,12
df,78
teu,54
etr,12
If delete(df) is called then nthentry(2) should return teu


Please suggest the solution ..

-- 




Re: [algogeeks] Adobe written test question

2012-10-25 Thread Nishant Pandey
i think arr[10] and int *arr are two different declaration when ,when
compiler tried to link with the memory of int arr[10] it could nt find it ,
as u have declraed it to be integer type pointer , and in file 1 it could
find integer pointer .

On Wed, Oct 24, 2012 at 11:06 PM, rahul sharma rahul23111...@gmail.comwrote:

 int arr[10] // in fyl 1

 now in fyl 2

 extern int *arr
 void foo()
 {
 arr[0]=10;
 }
 what kind of problem can be there?in what condition and y?

 plz comment

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: [Google] Finds all the elements that appear more than n/3 times

2012-07-11 Thread Nishant Pandey
can some body please explain voting algo to me .

On Wed, Jul 11, 2012 at 12:42 PM, Navin Kumar algorithm.i...@gmail.comwrote:

 @sachin:


 http://valis.cs.uiuc.edu/~sariel/research/CG/applets/linear_prog/median.html

 On Wed, Jul 11, 2012 at 12:28 PM, sachin goyal 
 sachingoyal@gmail.comwrote:

 To Mr. B
 how will you find median in O(n) time? please elaborate.


 On Wednesday, July 11, 2012 4:01:43 AM UTC+5:30, Mr.B wrote:

 I found a similar solution looking somewhere else.

 The solution for this problem is:
 a. There can be atmost 3 elements (only 3 distinct elements with each
 repeating n/3 times) -- check for this and done. -- O(n) time.
 b. There can be atmost 2 elements if not above case.

 1. Find the median of the input. O(N)
 2. Check if median element is repeated N/3 times or more -- O(n) - *{mark
 for output if yes}*
 3. partition the array based on median found above. - O(n)  --
 {partition is single step in quicksort}
 4. find median in left partition from (3). - O(n)
 5. check if median element is repeared n/3 times or more - O(n)  *{mark
 for output if yes}*
 6. find median in right partition from (3). - O(n)
 7.  check if median element is repeared n/3 times or more - O(n)  *{mark
 for output if yes}*

 its 7*O(N) = O(N) solution. Constant space.

 we need not check further down or recursively. {why? reason it.. its
 simple}


 On Wednesday, 27 June 2012 18:35:12 UTC-4, Navin Kumar wrote:


 Design an algorithm that, given a list of n elements in an array, finds
 all the elements that appear more than n/3 times in the list. The algorithm
 should run in linear time

 ( n =0 ).

 You are expected to use comparisons and achieve linear time. No
 hashing/excessive space/ and don't use standard linear time deterministic
 selection algo.

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/PxIJd3So3tkJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Finding intersection of 2 linked lists

2012-07-05 Thread Nishant Pandey
both the distance means distance between the two linked list some thing
like this :



struct node *temp1,*temp2;
temp1 = head1;
temp2 = head2;

int l1 = get_dist(head1);
int l2 = get_dist(head2);

int ds = abs(l1-l2);
if( l1  l2 )
{

   for(int i=0;ids;i++)
  {
 if(temp1-next)temp1 = temp1-next;
  }
  // here distance of both the list is equal .
  // now you may traverse like this
   while(temp1  temp2)
   {
   if(temp1 == temp2 )
 // intersection point
  else
   temp1 = temp1-next;
   temp2 = temp2-next;
  // move both one one step a time will come both will meet the
intersection point
  // i hope the point is clear if not let me knw i will send u
the whole code .
   }
}
else
{
   // similary for (l1l2)
}


On Thu, Jul 5, 2012 at 4:32 PM, Abhishek Sharma abhi120...@gmail.comwrote:

 @nishant, you wrote until both the distance becomes equal.Which
 distances ? Could you please elaborate ?


 On Thu, Jul 5, 2012 at 12:52 PM, Ashish Goel ashg...@gmail.com wrote:

 struct node* intersection( struct node *pL1, struct node* pL2)
 {
if ((!pL1) || (!pl2)) return NULL;
struct node * pL3 = NULL;
struct node* pL3Tail = NULL;
while(pL1)(pL2) {
 if (pL1-data pL2-data) pL1=pL1-next;
 else if  (pL1-data  pL2-data) pL2=pL2-next;
 else {
struct node *pNew = (struct node*)malloc(sizeof(struct node));
if !pNew return NULL; //scary
pNew-data = pL1-data; pNew-next = NULL;
if ( !pL3) pL3= pNew;
else pL3Tail-next = pNew;
pL3Tail = pNew;
}
return pL3;
 }




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


 On Wed, Jul 4, 2012 at 10:41 PM, Abhi abhi120...@gmail.com wrote:

 Any efficient algorithm to find intersection of two linked
 lists.Example:
 Linked List 1)  1 - 2 - 3 - 4 - 5 - 6
 Linked List 2)  3 - 4 - 5

 Intersection 4 - 5 - 6

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/-8_lnGA-ZhgJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 Abhishek Sharma
 Under-Graduate Student,
 PEC University of Technology

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] Permuatation of string in caase of duplicte string it shouldnt print duplicates permutation .

2012-07-04 Thread Nishant Pandey
the code works fine only in case of duplicates , but if we consider
string to be non duplicates like say :abc then all permutation cant be
obtainned .

On Wed, Jul 4, 2012 at 12:31 PM, atul anand atul.87fri...@gmail.com wrote:

 you can use flag[256];

 now you just need to check
 loop:
 if (flag[str[i]]==0)
 {
  //swap()
  //permute function call
  //swap()
  flag[str[i]=1;
 }
 done


 On 7/4/12, atul anand atul.87fri...@gmail.com wrote:
  you can use flag[256];
 
  now you just need to check
  loop:
  flag[str[i]]==0)
  {
   //swap()
   //permute function call
   //swap()
   flag[str[i]=1;
  }
  done
 
  On 7/3/12, Nishant Pandey nishant.bits.me...@gmail.com wrote:
  1) Find all permutations of a string.
  2) Improve it so that the permutations are not repeated, Eg= string is
  
  Answer should be just  once not 4! times.
 
  i want suggestion to improve the recursive code in case of 2) case .
 
  --
  You received this message because you are subscribed to the Google
 Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.
 
 
 

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Finding intersection of 2 linked lists

2012-07-04 Thread Nishant Pandey
get the size  of both the linked list say d1,d2 ;
get their diff like df=abs(d1-d2);

now take 2 pointers both poiting to the start of both the linked list .
go to bigger list now move this pointer until both the distance becomes
equal .
at this point we have one pointer from smaller list pointing to the start
of the list and
another pointer in bigger list pointing to node where distance came equal ,
move these 2 pointers until both point to the same node .. and we are done .

On Wed, Jul 4, 2012 at 10:44 PM, Amit Chauhan amitchauhan@gmail.comwrote:

 If both the linked list are ordered one then you can solve this problem in
 linear time and with constant space.



 On Wed, Jul 4, 2012 at 10:41 PM, Abhi abhi120...@gmail.com wrote:

 Any efficient algorithm to find intersection of two linked lists.Example:
 Linked List 1)  1 - 2 - 3 - 4 - 5 - 6
 Linked List 2)  3 - 4 - 5

 Intersection 4 - 5 - 6

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/-8_lnGA-ZhgJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Permuatation of string in caase of duplicte string it shouldnt print duplicates permutation .

2012-07-03 Thread Nishant Pandey
1) Find all permutations of a string.
2) Improve it so that the permutations are not repeated, Eg= string is

Answer should be just  once not 4! times.

i want suggestion to improve the recursive code in case of 2) case .

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Inorder Iterative code for printing paths

2012-06-28 Thread Nishant Pandey
thanx amitesh code is working fine .. i was displaying it in other way not
like this , but yea it can be shown in this way too ..

On Thu, Jun 28, 2012 at 1:08 PM, Amitesh Singh singh.amit...@gmail.comwrote:

 and to count no. of paths, you can do this
 void printPath(node *p,node *child)
 {
   static int iCountPath = 0; // or pass it as an argument non-const ref.
   if( p  child)
   {
 ++iCountPath;
 std::cout  Path:   p-data   =child-data 
 std::endl;
   }
 }

 --
 Amitesh




 On Thu, Jun 28, 2012 at 11:01 AM, Amitesh Singh 
 singh.amit...@gmail.comwrote:

 void printPath(node *p,node *child)
 {
   if( p  child)
 std::cout  Path:   p-data   =child-data 
 std::endl;
 }

 use  this before you assign 'current' to its children.
 e.g.

printPath(p,p-left)
or
printPath(p,p-right);


 --
 Amitesh




 On Mon, Jun 25, 2012 at 11:34 PM, Nishant Pandey 
 nishant.bits.me...@gmail.com wrote:


 thiss is iterative inorder  code i am using for printing all the paths
 of the Btree .

 but i am not able to manipulate the lengths properly when its perform
 pop up so that i
 can print the paths properly ..

 Can any one help by modifying the changes in this code .



 void inorder(struct node *root)
 {
 stackstruct node*stack_temp;

 struct node *current,*temp;
 int path[20];
 int i =0 ,j=0;
 if(!root)return ;

 current=root;
 bool flag=false;
 //bool ctrl=false;
 while(!flag)
 {

 if(current)
 {
 //coutcurrent-dataendl;
 stack_temp.push(current);
 path[i++]=current-data;
 if(current-left == NULL  current-right == NULL)
 {
 for(j=0;ji;j++)
 coutpath[j] ;
 //i--;

 }

 coutendl;
 current=current-left;

 }
 else
 {
 if(stack_temp.empty())
 {
 flag=true;
 }
 else
 {
 current=stack_temp.top();
 stack_temp.pop();

 i--;


 //if(current-right)
 //coutcurrent-dataendl;
 current=current-right;
 if(current)
 i++;
 }

 }

 }


 }



 --
 Cheers,

 Nishant Pandey |Specialist Tools Development  |  
 npan...@google.comgvib...@google.com |
 +91-9911258345


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Inorder Iterative code for printing paths

2012-06-25 Thread Nishant Pandey
thiss is iterative inorder  code i am using for printing all the paths of
the Btree .

but i am not able to manipulate the lengths properly when its perform pop
up so that i
can print the paths properly ..

Can any one help by modifying the changes in this code .



void inorder(struct node *root)
{
stackstruct node*stack_temp;

struct node *current,*temp;
int path[20];
int i =0 ,j=0;
if(!root)return ;

current=root;
bool flag=false;
//bool ctrl=false;
while(!flag)
{

if(current)
{
//coutcurrent-dataendl;
stack_temp.push(current);
path[i++]=current-data;
if(current-left == NULL  current-right == NULL)
{
for(j=0;ji;j++)
coutpath[j] ;
//i--;

}

coutendl;
current=current-left;

}
else
{
if(stack_temp.empty())
{
flag=true;
}
else
{
current=stack_temp.top();
stack_temp.pop();

i--;


//if(current-right)
//coutcurrent-dataendl;
current=current-right;
if(current)
i++;
}

}

}


}



-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread Nishant Pandey
can this be done in single pass in O(n) .

On Thu, Jun 21, 2012 at 8:10 PM, rusty dafc1...@gmail.com wrote:

 guys this is my solution to the problem, it's a bit sloppy but as far as I
 checked it was working please have a go at it?


 #include stdio.h
 #include stdlib.h

 int main() {
 int arr1[] = {0,-5,3,0,4,-6,-9};
 int arr2[7];
 int j = 0;
 for ( int i = 0 ; i  7 ; i++ ) {
 //loop for -ve numbers
 if ( arr1[i]  0 )
 arr2[j++] = arr1[i];

 }

 //accomodate all the zeros if any
 for ( int i = 0 ; i  7 ; i++ ) {
 if ( arr1[i] == 0 )
 arr2[j++] = arr1[i];
 }
 for ( int i = 0 ; i  7 ; i++ ) {
 //loop for +ve numbers
 if ( arr1[i]  0 )
 arr2[j++] = arr1[i];

 }
 //print arr1 for reference
 printf(\nInitially the array was);
 for ( int i = 0 ; i  7 ; i++ )
 printf(\narr1[%d]: %d,i,arr1[i]);
 printf(\n\n);
 //print arr2
 for ( int i = 0 ; i  7 ; i++ )
 printf(\narr2[%d]: %d,i,arr2[i]);

 return 0;

 }

 On Wednesday, June 13, 2012 9:49:49 PM UTC+5:30, Krishna Kishore wrote:

 Given a array of integers both positive and negative and you need to
 shift positive numbers to one side
 and negative numbers to other side with the order intact.
 ex. {-1,5,3,-8,4,-6,9} to {-1,-8,-6,5,3,4,9}. This should be done in O(n).

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/H8ANlbL0dmEJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread Nishant Pandey
i mean o(n) in single traversal .

On Fri, Jun 22, 2012 at 12:53 AM, sanjay pandey
sanjaypandey...@gmail.comwrote:

 single traversal n O(n) are 2 diff things...plz specify???

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Directi question-centre of the tree

2012-06-20 Thread Nishant Pandey
I am asking again .. can any one please suggest better method for getting
the median on the longest path of the tree ..
efficient method .

On Tue, Jun 19, 2012 at 5:08 PM, Nishant Pandey 
nishant.bits.me...@gmail.com wrote:


 for getting diameter we can simply add the max height of left subtree and
 max height of the right sub tree .

 the main issue is how efficiently we find median on that longest path to
 get the center of the tree .
 can any bdy sugest optimized algo for that ?


 On Mon, Jun 18, 2012 at 6:08 PM, rajesh pandey 
 rajesh.pandey.i...@gmail.com wrote:

 I found it in some paper ;)

  Diameter and center
 De nition 4. The diameter of tree is the length of the longest path.
 De nition 5. A center is a vertex v such that the longest path from v to
 a leaf is minimal
 over all vertices in the tree.Tree center(s) can be found using simple
 algorithm.
 Algorithm 1. (Centers of tree)
 1: Choose a random root r.
 2: Find a vertex v1 | the farthest form r.
 3: Find a vertex v2 | the farthest form v1.
 4: Diameter is a length of path from v1 to v2.
 5: Center is a median element(s) of path from v1 to v2.

 This is O(n) algorithm. It is clear that we can't determine tree
 isomorphism faster
 than O(n). So, if we nd a O(f(n)) algorithm for rooted trees isomorphism
 we can also
 obtain O(f(n)) algorithm for ordinary trees.

 On Saturday, June 16, 2012 12:04:32 PM UTC+5:30, achala sharma wrote:

 I think this algorithm is used for calculating poset in graph.

 On Sat, Jun 16, 2012 at 3:04 AM, Hemesh Singh hemesh.mn...@gmail.comwrote:

 + 1 for DK's solution. Is that a standard algorithm coz I feel like I
 have heard it somewhere ??


 On Mon, Aug 8, 2011 at 1:37 AM, DK divyekap...@gmail.com wrote:

 @KK: DFS and BFS are O(N) and Floyd Warshall is O(N^3).
 Could you please state how you can use the traversals directly to get
 the center? (And prove your correctness too?)

 The solution given by Wladimir ( expanded upon by me) is O(N) and
 uses (somewhat) the inverse of a BFS as a traversal.

 --
 DK

 http://twitter.com/divyekapoor
 http://gplus.to/divyekapoor
 http://www.divye.in

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To view this discussion on the web visit https://groups.google.com/d/*
 *msg/algogeeks/-/HnMOZtOrkqwJhttps://groups.google.com/d/msg/algogeeks/-/HnMOZtOrkqwJ.


 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to algogeeks+unsubscribe@**
 googlegroups.com algogeeks%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en
 .




 --
 Hemesh singh

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to algogeeks+unsubscribe@**
 googlegroups.com algogeeks%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/BWplK7bCatMJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

 Nishant Pandey |Specialist Tools Development  |  
 npan...@google.comgvib...@google.com |
 +91-9911258345





-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Directi question-centre of the tree

2012-06-19 Thread Nishant Pandey
for getting diameter we can simply add the max height of left subtree and
max height of the right sub tree .

the main issue is how efficiently we find median on that longest path to
get the center of the tree .
can any bdy sugest optimized algo for that ?

On Mon, Jun 18, 2012 at 6:08 PM, rajesh pandey rajesh.pandey.i...@gmail.com
 wrote:

 I found it in some paper ;)

  Diameter and center
 De nition 4. The diameter of tree is the length of the longest path.
 De nition 5. A center is a vertex v such that the longest path from v to a
 leaf is minimal
 over all vertices in the tree.Tree center(s) can be found using simple
 algorithm.
 Algorithm 1. (Centers of tree)
 1: Choose a random root r.
 2: Find a vertex v1 | the farthest form r.
 3: Find a vertex v2 | the farthest form v1.
 4: Diameter is a length of path from v1 to v2.
 5: Center is a median element(s) of path from v1 to v2.

 This is O(n) algorithm. It is clear that we can't determine tree
 isomorphism faster
 than O(n). So, if we nd a O(f(n)) algorithm for rooted trees isomorphism
 we can also
 obtain O(f(n)) algorithm for ordinary trees.

 On Saturday, June 16, 2012 12:04:32 PM UTC+5:30, achala sharma wrote:

 I think this algorithm is used for calculating poset in graph.

 On Sat, Jun 16, 2012 at 3:04 AM, Hemesh Singh hemesh.mn...@gmail.comwrote:

 + 1 for DK's solution. Is that a standard algorithm coz I feel like I
 have heard it somewhere ??


 On Mon, Aug 8, 2011 at 1:37 AM, DK divyekap...@gmail.com wrote:

 @KK: DFS and BFS are O(N) and Floyd Warshall is O(N^3).
 Could you please state how you can use the traversals directly to get
 the center? (And prove your correctness too?)

 The solution given by Wladimir ( expanded upon by me) is O(N) and uses
 (somewhat) the inverse of a BFS as a traversal.

 --
 DK

 http://twitter.com/divyekapoor
 http://gplus.to/divyekapoor
 http://www.divye.in

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To view this discussion on the web visit https://groups.google.com/d/**
 msg/algogeeks/-/HnMOZtOrkqwJhttps://groups.google.com/d/msg/algogeeks/-/HnMOZtOrkqwJ.


 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to algogeeks+unsubscribe@**
 googlegroups.com algogeeks%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en.




 --
 Hemesh singh

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to algogeeks+unsubscribe@**
 googlegroups.com algogeeks%2bunsubscr...@googlegroups.com.
 For more options, visit this group at http://groups.google.com/**
 group/algogeeks?hl=en http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/BWplK7bCatMJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Can anyone plz explain how we get this output

2012-06-14 Thread Nishant Pandey
this is something which is compiler dependent ,its answer may vary
depending upon
the implementation of compiler .

On Thu, Jun 14, 2012 at 11:41 AM, Ajesh js coolajes...@gmail.com wrote:

 main()
 {
int a=10,b=5;
printf(%d %d %d\n,a++,a,++a);
printf(%d %d %d\n,++b,b,b++);
 }

 output
 11 12 12
 7 7 5

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
the steps would be like this :
if i say stack is like this 1,2,3,4 then
1) pop each and every item from the stack till stack is empty
the nodes will be ther in function call stack stil  not pushed

2) now now take elements from function call stack like 4 and push it
3) when 3 comes next time first pop 4 and then push 3 again
4) repeat the step 3 again till the function call stack in not empty .

and uir done .

On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel ashg...@gmail.com wrote:


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

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
stack means inbuild stack we cant use any DS from our program explicitly.

On Thu, Jun 14, 2012 at 2:44 PM, rahul patil
rahul.deshmukhpa...@gmail.comwrote:

 to store items in stack you will need some DS. Do they mean you cant use
 any auxillary DS than stack ?


 On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel ashg...@gmail.com wrote:


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

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,
 Rahul Patil

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
i think i already explained the logic initially :)

On Thu, Jun 14, 2012 at 9:30 PM, Hassan Monfared hmonfa...@gmail.comwrote:

 how can you pop from empty stack ?
   temp=pop(S); 

 Regards,
 Hassan

 On Thu, Jun 14, 2012 at 8:25 PM, Ashish Goel ashg...@gmail.com wrote:

 Navin: copy pastes not encouraged till the logic is also clarified ;)

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


 On Thu, Jun 14, 2012 at 7:25 PM, Sourabh Singh 
 singhsourab...@gmail.comwrote:

 @ Navin Kumar

 Nice . Solution.
 But
 your  function also make a stack only. so you are using a
 stack[internal] here.
 but may be this one is allowed:-)


 On Thu, Jun 14, 2012 at 5:23 AM, Navin Kumar 
 algorithm.i...@gmail.comwrote:

 void Reverse(struct Stack *S) {
 int data;
 if(IsEmptyStack(S)) return;
 data=pop(s);
 ReverseStack(S);
 InsertAtBottom(S, data);
 }

 void InsertAtBottom(struct stack *S, int data)
 {
int temp;
if(!IsEmptyStack(S)){
push(S,data);
return;
 }
temp=pop(S);
InsertAtBottom(S,data);
 push(S, temp);

 }


 On Thu, Jun 14, 2012 at 2:44 PM, rahul patil 
 rahul.deshmukhpa...@gmail.com wrote:

 to store items in stack you will need some DS. Do they mean you cant
 use any auxillary DS than stack ?


 On Thu, Jun 14, 2012 at 2:24 PM, Ashish Goel ashg...@gmail.comwrote:


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

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,
 Rahul Patil

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Adobe interiew question

2012-06-13 Thread Nishant Pandey
i dont think goto will  be a good option , there might be a situation where
your program may get stuck jumping
on the labels , performance will get hampered , i feel singnals are good
options to go for it .

On Wed, Jun 13, 2012 at 12:37 PM, Raghavendhra Chowdary MV 
raghavendhra20061...@gmail.com wrote:

 How about using goto label?? and at label using a switch case with respect
 to turn around with values??


 On Wed, Jun 13, 2012 at 11:56 AM, Amitesh Singh 
 singh.amit...@gmail.comwrote:

 signals and logjmp/setjmp()

 --
 Amitesh




 On Wed, Jun 13, 2012 at 10:40 AM, saurabh singh saurab...@gmail.comwrote:

 tHE first thing that comes in my mind Signals
 Saurabh Singh
 B.Tech (Computer Science)
 MNNIT
 blog:geekinessthecoolway.blogspot.com



 On Tue, Jun 12, 2012 at 10:26 PM, Shashank Narayan 
 shashank7andr...@gmail.com wrote:

 yes u can review that link :)

 On Tue, Jun 12, 2012 at 9:47 PM, Anika Jain anika.jai...@gmail.comwrote:

 how can we implement exception handling in c?

 --
 Regards
 Anika Jain

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Thanks
 Shashank Mani Narayan
 Computer Science  Engineering
 Birla Institute of Technology,Mesra
 ** Founder Cracking The Code Lab  http://shashank7s.blogspot.com/;
 FB Page http://www.facebook.com/pages/Cracking-The-Code/148241881919895
 Google+ http://gplus.to/wgpshashank
  Twitter 
 https://twitter.com/wgpshashankhttps://twitter.com/#%21/wgpshashank
 
 Puzzled Guy @ http://ashutosh7s.blogspot.com**
 **FB Page http://www.facebook.com/Puzzles.For.Puzzled.Minds*
 * Key Person Algogeek https://groups.google.com/forum/#!forum
 /algogeeks https://groups.google.com/forum/#%21forum/algogeeks
 **Cell +91-9740852296
 *


 *
 **
 *

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 Thanks  Regards,
 M.V.Raghavendhra Chowdary.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] [amazon]: dutch national flag algorithm

2012-06-10 Thread Nishant Pandey
it can be solved in o(n) , keep one pointer at start and another pointer at
the last ,
traverse the string if u get R swap it at the start position and then
increament it ,
if u get B swap it with last pointer pointing to last position .and then
decrement it .
in this way all things will come in place .

On Sat, Jun 9, 2012 at 11:36 PM, Navin Kumar algorithm.i...@gmail.comwrote:

 Given a character array as input. Array contains only three types of
 characters 'R', 'G' and 'B'. Sort the array such that all 'R's comes before
 'G's and all 'G's comes before 'B's.

 Constraint :- No extra space allowed(except O(1) space like variables) and
 minimize the time complexity.
 You can only traverse the array once.

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

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] first Repeating character in a string

2012-06-08 Thread Nishant Pandey
the output will be correct it will not be incorrect in hashing case .

On Fri, Jun 8, 2012 at 2:38 PM, atul anand atul.87fri...@gmail.com wrote:

 howcome hashing will result in wrong output..??

 if(isHashed(str[i])
 {
  character found.
 break.
 }
 else
   hash(str[i]);

 On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal 
 himanshukansal...@gmail.com wrote:

 how can we find 1st repeating character in string???
 e.g. if the string is abba it should return 'b' and not 'a'.

 note: hashing will give the answer as 'a'

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] first Repeating character in a string

2012-06-08 Thread Nishant Pandey
you may use look up table for each character like this :

int table[255]={0};

for(int i=0;str[i];i++)
{
if( table[str[i]] )
return true;
   else
{
table[str[i]]=1;
}

}
return false;


On Fri, Jun 8, 2012 at 2:26 PM, Anika Jain anika.jai...@gmail.com wrote:

 you will have to note time for of occurence of a character for all chars


 On Fri, Jun 8, 2012 at 2:15 PM, himanshu kansal 
 himanshukansal...@gmail.com wrote:

 how can we find 1st repeating character in string???
 e.g. if the string is abba it should return 'b' and not 'a'.

 note: hashing will give the answer as 'a'

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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
 Anika Jain

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Simple Question ,Find Error

2012-06-04 Thread Nishant Pandey
actually the address of name is constant and that get modifed , so
thats not possible once name is converted to pointer then this assignment
is posible .

On Mon, Jun 4, 2012 at 10:51 AM, Hassan Monfared hmonfa...@gmail.comwrote:

 you can't assign  value into names[i]!


 On Mon, Jun 4, 2012 at 3:12 AM, mahendra sengar sengar.m...@gmail.comwrote:

  main()
 {
 static char names[5][20]={pascal,ada,cobol,fortran,perl};
 int i;
 char *t;
 t=names[3];
 names[3]=names[4];
 names[4]=t;
 for (i=0;i=4;i++)
 printf(%s,names[i]);
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] LINKED LIST QUESTION

2012-06-04 Thread Nishant Pandey
Hi ,

I think the only possiblity is to make it doubly linked list and then
consider next  prev as left and right child like tree and then perform
search as we in tree , it would serve the purpose .
let me know if iam wrong .

On Mon, Jun 4, 2012 at 3:51 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:

 can be done using skip lists


 On Mon, Jun 4, 2012 at 3:03 PM, Jeevitesh jeeviteshshekha...@gmail.comwrote:

 This is possible only if Linked List is sorted then we can apply Merge
 Sort for Linked List which would be in place.

 Otherwise the time complexity would be O(n logn).

 On Mon, Jun 4, 2012 at 3:00 PM, VIHARRI viharri@gmail.com wrote:

 Hi we need find a node in linked list in O(logn). You can change the
 list as u like.

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/vSoEXlaRTEIJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Thanks,
 Jeevitesh Shekhar Singh.*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Linked list using void pointer

2012-05-31 Thread Nishant Pandey
this way u can do it in c  creation and printing of generic lisk list .

void(List **p,void *data, unsigned int n)
{
List *temp;
int i;

/* Error check is ignored */
temp = malloc(sizeof(List));
temp-data = malloc(n);
for (i = 0; i  n; i++)
*(char *)(temp-data + i) = *(char *)(data + i);
temp-next = *p;
*p = temp;
}

void(List *p,void (*f)(void*))
{
while (p)
{
(*f)(p-data);
p = p-next;
}
}


void printstr(void *str)
{
printf( \%s\, (char *)str);

}

Regads
Nishant Pandey

On Thu, May 31, 2012 at 1:15 PM, Hassan Monfared hmonfa...@gmail.comwrote:

 Why don't you use templates ?
 
 template class T
 class LNode
 {
 public:
 LNode(T pData,LNode *pNext):data(pData),next(pNext){}
  T data;
 LNode *next;
 };
 template class T
 class LList
 {
 protected:
 LNodeT *head;
 LNodeT *tail;
 public:
 LList()
 {
 head=tail=NULL;
  }

 void push_back(T pData)
 {
  if(head==NULL)
 {
 head=tail=new LNodeT(pData,NULL);
  return;
 }
 tail-next=new LNodeT(pData,NULL);
  tail=tail-next;
 }
 void push_front(T pData)
  {
 if(head==NULL)
 {
  head=tail=new LNodeT(pData,NULL);
 return;
 }
  LNodeT *nnode=new LNodeT(pData,head);
 head=nnode;
 }
  void Print()
 {
 LNodeint *cur=head;
  while(cur)
 {
 coutcur-data',';
  cur=cur-next;
 }
 cout  endl;
  }
 void Reverse()
 {
  LNodeT *cur=head;
 LNodeT *prev=NULL;
 LNodeT *tmp;
  while(cur)
 {
 tmp=cur-next;
  cur-next=prev;
 prev=cur;
 cur=tmp;
  }
 tmp=head;
 head=prev;
  tail=tmp;
 }
 };

 Regards

 On Thu, May 31, 2012 at 8:49 AM, mahendra sengar sengar.m...@gmail.comwrote:

 how to implement generioc linked list..using void pointer...i havent
 used void pointer much so, m not able to use it properly in linked
 list..please help asap !!!

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] MS Question: Delete a node in single linked list if it is less than any of the successor nodes

2012-05-31 Thread Nishant Pandey
if i am getting this questions correctly then we have to delete the element
till its next is not null ??
please comment if i am wrong ?

On Thu, May 31, 2012 at 5:58 PM, Ashish Goel ashg...@gmail.com wrote:

 that is what i have done by using recursion=stack.

 my code has problem, after  free(pCurr);, i should have return pRest;

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


 On Thu, May 31, 2012 at 4:37 PM, atul anand atul.87fri...@gmail.comwrote:

 then i guess ...it can be done using stack..with O(n) complexity..
 it is similar to finding next greater element 

 http://www.geeksforgeeks.org/archives/8405

 element in the stack at the end of the algo...are the element which will
 remain in the linked list . if stack is not empty then keep poping elements
 and create a SLL.


 On Thu, May 31, 2012 at 4:29 PM, Ashish Goel ashg...@gmail.com wrote:

 yes

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


 On Thu, May 31, 2012 at 2:34 PM, atul anand atul.87fri...@gmail.comwrote:

 @Ashish :  please clarify this ques...

 delete a node in SLL if it is less than *any* of the succesor node ..

 1 2 8 10 3 4 7 12

 delete 1,2,8,10,3,4,7

 ouput will be single node i.e 12

 dats what question asks?

 On Thu, May 31, 2012 at 2:16 PM, Ashish Goel ashg...@gmail.com wrote:

 the LL is unsorted, is there any better solution that this?

 struct node* deleteNodes(struct node *pHead, struct node *pPrev)
 {
   struct  node *pLL = *pHead;
   if (!pLL) return NULL;
   struct node *pCurr = pLL;

   struct node *pRest = deleteNodes(pCurr-next, pCurr);
   if (!pRest) return pCurr;
   if (pCurr-data pRest-data)
   {
 if (pPrev) { pPrev-next = pRest; };
 free(pCurr);
   }
  else
  {
pCurr-next = pRest;
  }
return pCurr;
 }


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

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] Linked list using void pointer

2012-05-31 Thread Nishant Pandey
in case of generic link list when u have to create the node u have to copy
the data part character by character ie always one -one byte and in this
way whatever be the data type of ur data u can easily get the data and
u will keep  doing this until the size of the data that to entered .

On Thu, May 31, 2012 at 9:49 AM, mahendra sengar sengar.m...@gmail.comwrote:

 how to implement generioc linked list..using void pointer...i havent
 used void pointer much so, m not able to use it properly in linked
 list..please help asap !!!

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: C Doubts

2011-07-18 Thread Nishant Mittal
@abhi
we can do it without passing the address to a function. just store the
address of const variable in another variable and change the value...

On Mon, Jul 18, 2011 at 11:56 AM, Abhi abhi123khat...@gmail.com wrote:

 Perhaps the only way to alter the value of a variable declared constant in
 C is through passing its address to a function and changing the value
 henceforth though it generates a warning of 'discarding the qualifiers'.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/SbHlNcA7Fj8J.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] Missing Number in an array

2011-07-18 Thread Nishant Mittal
1.Calculate XOR of all the array elements.
2.XOR the result with all numbers from 1 to n =x1
3.After 2nd step, all elements would nullify each other except 2 missing
elements(let x and y) and x1 will contain XOR of x and y
4.All the bits that are set in x1 will be set in either x or y. Get the
rightmost set bit from x1.
5.divide the elements of the array in two sets – one set of elements with
same bit set and other set with same bit not set. By doing so, you will get
x in one set and y in another set.
6.XOR all the elements of 1st set with the numbers between 1 to n which have
same bit set and XOR the 2nd set with the numbers between 1 to n which have
same bit not set. Now result of both set will have the desired result


On Mon, Jul 18, 2011 at 5:57 PM, varun pahwa varunpahwa2...@gmail.comwrote:

 sorry that would not work. only it could work if each element is present
 exactly once.


 On Mon, Jul 18, 2011 at 5:44 PM, Aakash Johari aakashj@gmail.comwrote:

 Yes, you will have to write a quad eq. solver. It's easy to write.


 On Mon, Jul 18, 2011 at 5:13 AM, Aakash Johari aakashj@gmail.comwrote:

 @varun: can you write the code for one?


 On Mon, Jul 18, 2011 at 5:11 AM, varun pahwa 
 varunpahwa2...@gmail.comwrote:

 The above solution will work if each other number is exactly once
 present. but if that 's not true.
 then 4 equations can be formed.
 Assuming a,b repeated number where a may or may be equal to b.

 then equations will be
 x + y = a + b;
 x^2 + y^2 = a^2 + b^2.
 x.y = a.b
 x^3 + y^3 = a^3 + b^3.
 now 4 equations 4 variables can be solved.


 On Mon, Jul 18, 2011 at 5:31 PM, ankit sambyal 
 ankitsamb...@gmail.comwrote:

 1. Initialize a bit vector of size n.
 2. For every no. set the corresponding bit vector.
 3. Now scan through the bit vectors and get the missing numbers
 corressponding to the unset bits in the bit vector.


 Time complexity : O(n)

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Varun Pahwa
 B.Tech (IT)
 7th Sem.
 Indian Institute of Information Technology Allahabad.
 Ph : 09793899112
 Official Email :: rit2008...@iiita.ac.in
 Another Email :: varunpahwa.ii...@gmail.com

 People who fail to plan are those who plan to fail.

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 -Aakash Johari
 (IIIT Allahabad)







 --
 -Aakash Johari
 (IIIT Allahabad)




  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Varun Pahwa
 B.Tech (IT)
 7th Sem.
 Indian Institute of Information Technology Allahabad.
 Ph : 09793899112
 Official Email :: rit2008...@iiita.ac.in
 Another Email :: varunpahwa.ii...@gmail.com

 People who fail to plan are those who plan to fail.

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Missing Number in an array

2011-07-18 Thread Nishant Mittal
@ankit...i m assuming that array of size n contains n-2 elements with 2
elements missing

On Mon, Jul 18, 2011 at 6:07 PM, SAMMM somnath.nit...@gmail.com wrote:

 #includestdio.h
 int main()
 {

 int a[]={1,2,3,5,2}; // 2 isrepeated and 4 is missing
 int i=0,x=0,j=0,bit;
 while(i5)
 {
 j^=i+1;j^=a[i];
 i++;
 }

 bit=j~(j-1);  //set bits

 i=0;j=0;

 while(i5)
 {
 if(bit(i+1)) x^=(i+1);//two set are needed to iterate
 else j^=(i+1); //two set are needed to iterate
 i++;
 }
 i=0;
 while(i5)
 {
 if(bita[i]) x^=a[i];   //two set are needed to iterate
 else j^=a[i];  //two set are needed to iterate
 i++;
 }

 printf(%d %d,x,j);
 return 0;
 }

 Hav a look  The trick is in the  set bit   [ bit=j~(j-1);  //set
 bits]

 On Jul 18, 4:31 pm, TUSHAR_MCA tusharkanta.r...@gmail.com wrote:
  Given an array of size n. It contains numbers in the range 1 to n.
  Each number is present at least once except for 2 numbers. Find the
  missing numbers ?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Missing Number in an array

2011-07-18 Thread Nishant Mittal
ok then 1st remove duplicates from the array in O(n) then apply my algo...

On Mon, Jul 18, 2011 at 6:13 PM, ankit sambyal ankitsamb...@gmail.comwrote:

 @Nishant: Read the question carefully. It says Each number is present
 at least once except for 2 numbers.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Missing Number in an array

2011-07-18 Thread Nishant Mittal
@SkRiPt KiDdIe... I think you need to analyze my algo again it will work
for both the cases...

On Mon, Jul 18, 2011 at 6:33 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote:

 Nishant. Your algorithm works for finding repeated nos. in a [n+2] array
 where [1-n] are present atleast once and the same number is not being
 repeated twice.

 Reanalyze the question.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Missing Number in an array

2011-07-18 Thread Nishant Mittal
@ankit for removing duplicates=O(n)+O(n)


On Mon, Jul 18, 2011 at 6:36 PM, ankit sambyal ankitsamb...@gmail.comwrote:

 @nishant : Time complexity ?? will increase too much

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Missing Number in an array

2011-07-18 Thread Nishant Mittal
and for finding missing 2  elements= O(n)+O(n)+O(n)+O(n)
so total will be O(n)
but there will be no overflow


On Mon, Jul 18, 2011 at 6:41 PM, Nishant Mittal
mittal.nishan...@gmail.comwrote:

 @ankit for removing duplicates=O(n)+O(n)



 On Mon, Jul 18, 2011 at 6:36 PM, ankit sambyal ankitsamb...@gmail.comwrote:

 @nishant : Time complexity ?? will increase too much

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Missing Number in an array

2011-07-18 Thread Nishant Mittal
@SkRiPt KiDdIe... see my 3rd post...i've mentioned that 1st we have to
remove duplicate numbers

On Mon, Jul 18, 2011 at 6:56 PM, SkRiPt KiDdIe anuragmsi...@gmail.comwrote:


 @Nishant:

 1 4 5 4 5n=5

 1 2 3 4 5

 after xor i.e. your x1 answer contains (2^3^4^5).The missing elements
 are included in xor as well along with repeating elements.

 Hope now you got it. You are giving solution for a question which i have
 defined in previous post. and your algo will fail when
 the final xor has no set bit i.e.  same number is being repeated 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] Fwd: MICROSOFT INTERNSHIP (Coding round)

2011-07-18 Thread Nishant Mittal
start from top right corner... if a[i][j]  x then move left, else if
a[i][j]  x then move down and if a[i][j] == x then print i and j

On Mon, Jul 18, 2011 at 11:30 PM, sivaviknesh s sivavikne...@gmail.comwrote:



 -- Forwarded message --
 From: sivaviknesh s sivavikne...@gmail.com
 Date: Mon, Jul 18, 2011 at 11:29 PM
 Subject: Fwd: MICROSOFT INTERNSHIP (Coding round)
 To: algogeeks@googlegroups.com




 -- Forwarded message --
 From: subramania jeeva subramaniaje...@gmail.com
 Date: Thu, Sep 23, 2010 at 7:53 AM
 Subject: Re: MICROSOFT INTERNSHIP (Coding round)
 To: mitcse08i...@googlegroups.com


 Also in placement the question asked was

Given a 2 dimensional matrix with its rows and columns are
 in sorted order. You've to find a number and return its positions from that
 matrix...  I think the efficient way is binary search... It'll take log(n^2)
 to the base 4.

 Mostly they're expecting C code rather than C++ So
 improve your C knowledge..



 say

 1 2 3
 4 5 6
 7 8 9

 ...say u ve to find '8'

 start from 1 ...check its right (2) nd down (4)

 42 (but 48)so go to 4again check its right (5) nd down (7)

 75finally reached 8 in four stepscomplexity is less than o(m*n)...

 ...am i rite???








 Cheers
   ~ Jeeva ~



 --
 Regards,
 $iva




 --
 Regards,
 $iva

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] OUTPUT

2011-07-18 Thread Nishant Mittal
value of the static variable persists between different function call

On Mon, Jul 18, 2011 at 11:43 PM, geek forgeek geekhori...@gmail.comwrote:



 int main()
 {
 static int var = 5;
 printf(%d ,var--);
 if(var)
 main();
 }


 y output is 5 4 3 2 1

 not 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5

 y on each recursive call var is not initialized again.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] ms ques

2011-07-18 Thread Nishant Mittal
1st convert base 5 to base 10 and then base 10 to base 9

On Mon, Jul 18, 2011 at 11:54 PM, sivaviknesh s sivavikne...@gmail.comwrote:


 convert a number in base 5  to  base 9 

 --
 Regards,
 $iva

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] Reverse a List with Recursion

2011-07-17 Thread Nishant Mittal
void rev_recursion(NODE **head)
{
if(*head==NULL)
return;
NODE *first, *rest;
first=*head;
rest=first-next;
if(!rest)
return;
rev_recursion(rest);
first-next-next=first;
first-next=NULL;
*head=rest;
}

On Sun, Jul 17, 2011 at 2:53 PM, vaibhav shukla vaibhav200...@gmail.comwrote:

 struct node *reverse_recurse(struct node *start)
 {
   if(start-next)
   {
   reverse_recurse(start-next);
   start-next-next=start;
   return(start);
   }
   else
   {
   head=start;
   }
 }


 in main

 if(head)
 {
   temp = reverse_recurse(head);
   temp-next =NULL;
 }

 head and temp are global




 On Sun, Jul 17, 2011 at 2:42 PM, Navneet Gupta navneetn...@gmail.comwrote:

 Hi,

 I was trying to accomplish this task with the following call , header
 = ReverseList(header)

 I don't want to pass tail pointer or anything and just want that i get
 a reversed list with new header properly assigned after this call. I
 am getting issues in corner conditions like returning the correct node
 to be assigned to header.

 Can anyone give an elegant solution with above requirement? Since it
 is with recursion, please test for multiple scenarios (empty list, one
 node list, twe nodes



 list etc) before posting your solution. In case
 of empty list, the procedure should report that.

 --
 Regards,
 Navneet

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
   best wishes!!
 Vaibhav Shukla
 DU-MCA


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] MICROSOFT

2011-07-17 Thread Nishant Mittal
take 2 arrays before and after... before[i] contains the product of all the
numbers before i and after[i] contains product of all the numbers after i
something like this

before[0]=1;
after[n-1]=1;
for(i=1;in;i++)
{
before[i]=a[i-1]*before[i-1];
after[n-i-1]=after[n-i]*a[n-i];
}
   for(i=0;in;i++)
printf(%d\n,before[i]*after[i]);


On Sun, Jul 17, 2011 at 4:28 PM, geek forgeek geekhori...@gmail.com wrote:

 given an array a[0..n-1]  .required to find the output array out
 [0.n-1] such that out [i] is the product of all the numbers a[0] to
 a[n-1] excluding a[i]
 for ex out[2]=a[0]*a[1]*a[3]*a[4]a[n-1]
 constraint is not using division operator

 how to do this in O(n)??

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] MS question

2011-07-17 Thread Nishant Mittal
1.while typing it must show most popular searches starting from the string
which we have typed so far
2.it must show most popular websites first
3.it must show related searches

there can be many more

On Sun, Jul 17, 2011 at 8:05 PM, swetha rahul swetharahu...@gmail.comwrote:

 Write testcases for MSN search engine?

 help me to answer this...
 also can someone tell me how to answer this type of questions?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: MS question

2011-07-17 Thread Nishant
1.If string is NULL then it should return 1 i.e. string is palindrome
2.If there is only one character in string then it is palindrome
3.If reverse of given string is same as string

On Jul 17, 8:18 pm, swetha rahul swetharahu...@gmail.com wrote:
 ya got it..thanks...

 how abt test cases for program to check whether a given string is palindrome
 or not..?

 On Sun, Jul 17, 2011 at 8:35 PM, ankit sambyal ankitsamb...@gmail.comwrote:

  1. If u entered nothing and just pressed search, it should display nothing.
  2. If u just entered a space and just pressed search, it should display
  nothing.
  3.Verify the results are really related to give word or not
  4.Check if proper Result is displayed for key word.
  5. Check for the Order of the Result set, whether most relevant
  results are displayed first.

  --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from 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] MS:Linked list

2011-07-16 Thread Nishant Mittal
@sagar it will take O(n2) if all the elements of linked list are odd and
distinct..

On Sat, Jul 16, 2011 at 4:06 PM, sagar pareek sagarpar...@gmail.com wrote:

 i have solution with no extra space complexity but time complexity is O(n)

 traverse the list with a pointer ptr
 if odd no encounter then traverse the remaining list with tmp pointer with
 start point ptr-next and match the numbers with iti hope it works :)


 On Sat, Jul 16, 2011 at 10:10 AM, shady sinv...@gmail.com wrote:

 if hashing is allowed then it can be done in O(n)... space complexity
 in this case again will be O(n) this won't work for large numbers...


 On Sat, Jul 16, 2011 at 1:58 AM, Nishant Mittal 
 mittal.nishan...@gmail.com wrote:

 @sagar... I know this solution but it was strictly asked to do in O(n)
 time and O(1) space complexity and what if range of numbers is very
 large


 On Sat, Jul 16, 2011 at 1:09 AM, sagar pareek sagarpar...@gmail.comwrote:

 You just need to maintain the array for the odd words which encountered
 during traversing the list and using hashing this can be done :) but of
 course not in O(n) :(

 On Sat, Jul 16, 2011 at 12:51 AM, aseem garg ase.as...@gmail.comwrote:

 Use a Hash Table.
 Aseem



 On Sat, Jul 16, 2011 at 12:28 AM, shady sinv...@gmail.com wrote:

 i don't think it is possible to do it in O(n)... rather not even in
 O(nlogn) without modifying the list


 On Fri, Jul 15, 2011 at 11:23 PM, Nishant Mittal 
 mittal.nishan...@gmail.com wrote:

 How will you delete duplicate odd numbers from a linked list in O(n)
 time

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C OUTPUT AGAIN

2011-07-16 Thread Nishant Mittal
value of b = 10 (in binary) and since b is a signed integer and also MSB is
1 so final value of b is 2's complement of 10 i.e. -2

On Sun, Jul 17, 2011 at 12:55 AM, Kamakshii Aggarwal
kamakshi...@gmail.comwrote:

 @gaurav :y it is -2?y not +2?

 On Sat, Jul 16, 2011 at 2:13 PM, sukhmeet singh sukhmeet2...@gmail.comwrote:

 for problem1 you can use %hi or %hd .. while scanning ..


 On Thu, Jul 14, 2011 at 12:03 PM, Gaurav Jain gjainroor...@gmail.comwrote:

 @Nicks
 *Problem 1*

 %d is used to take a signed integer as input. To take a short integer as
 input, use %hi. That way, you would get the correct answer as 2.

 *Problem 2:*
 a:1 means that variable a is of width *1 bit*
 Similarly, b:2 means that b is of width *2 bits*

 b = 6 sets the two bits as 10, (last two bits of 110 considered), which
 is equal to -2
 a = 2 sets the only bit as 0, (last bit of 10 considered), which is
 nothing but zero.

 Bit-fields like these however tend to be implementation-dependent and in
 the interest of portability should be avoided.

 t.b = 6 sets the last two bits of b as 10, which is -2 in 2's complement
 t.a = 2 sets the
  On Thu, Jul 14, 2011 at 1:18 AM, nicks crazy.logic.k...@gmail.comwrote:

 Hey Guys, plz help me in getting these 2 C output problems

 *PROBLEM 1.*
 *
 *
 *#*includestdio.h
 int main()
 {
 short int a,b,c;
  scanf(%d%d,a,b);
 c=a+b;
 printf(%d,c);
  return 0;
 }
 INPUT-
 1 1

 OUTPUT
 1

 i am not getting why  1 is coming in the output.what difference is
 using short making in the code ???


 *PROBLEM 2.*
 *
 *
 *
 *
 #includestdio.h
 main()
 {
 struct
 {
  int a:1;
 int b:2;
 }t;
  t.b=6;
 t.a=2;
 printf(%d %d,t.a,t.b);
 }

 OUTPUT
 0 -2

 What does the statement  a:1 and b:1 mean and what are they doing.i
 am seeing them first time ever...hence not able to get the outputif
 someone has any idea plz help  !!

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Gaurav Jain
 Associate Software Engineer
 VxVM Escalations
 Symantec Software India Pvt. Ltd.



  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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,
 Kamakshi
 kamakshi...@gmail.com

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Linked list

2011-07-15 Thread Nishant Mittal
delete all the numbers found in list2 from list1 recursively or iteratively
Also optimize ur algo when list1 is sorted in ascending order and list2 is
sorted in descending order

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] MS:Linked list

2011-07-15 Thread Nishant Mittal
How will you delete duplicate odd numbers from a linked list in O(n) time

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] MS:Linked list

2011-07-15 Thread Nishant Mittal
@sagar... I know this solution but it was strictly asked to do in O(n) time
and O(1) space complexity and what if range of numbers is very large

On Sat, Jul 16, 2011 at 1:09 AM, sagar pareek sagarpar...@gmail.com wrote:

 You just need to maintain the array for the odd words which encountered
 during traversing the list and using hashing this can be done :) but of
 course not in O(n) :(

 On Sat, Jul 16, 2011 at 12:51 AM, aseem garg ase.as...@gmail.com wrote:

 Use a Hash Table.
 Aseem



 On Sat, Jul 16, 2011 at 12:28 AM, shady sinv...@gmail.com wrote:

 i don't think it is possible to do it in O(n)... rather not even in
 O(nlogn) without modifying the list


 On Fri, Jul 15, 2011 at 11:23 PM, Nishant Mittal 
 mittal.nishan...@gmail.com wrote:

 How will you delete duplicate odd numbers from a linked list in O(n)
 time

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] Linked list

2011-07-15 Thread Nishant Mittal
@surender thanx for ur algo but tell me about the 1st part when numbers are
not sorted.
i think if we apply merge sort on both the list then it would be easy to
delete after sorting.
correct me if i m wrong

On Sat, Jul 16, 2011 at 12:40 AM, surender sanke surend...@gmail.comwrote:

 count number of elements from both lists and reverse list with minimum
 number of elements, go ahead with checking and deleting linearly

 surender

 On Fri, Jul 15, 2011 at 10:38 PM, Nishant Mittal 
 mittal.nishan...@gmail.com wrote:

 delete all the numbers found in list2 from list1 recursively or
 iteratively
 Also optimize ur algo when list1 is sorted in ascending order and list2 is
 sorted in descending order

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Constructing a Binary Search Tree from Post Order traversal-Possible or not

2011-06-30 Thread Nishant
if BST contains integers then sort the postorder traversal which will
give you inorder traversal...

On Jun 30, 6:27 pm, oppilas . jatka.oppimi...@gmail.com wrote:
 Is it possible to create a binary search tree (not binary tree) from post
 order traversal only?
 If give, how and if not please give reason/counter examples.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] linked list

2011-06-29 Thread Nishant Mittal
segregate even and odd nodes in a singly linked list.Order of even and
odd numbers must be same...
e.g:-
i/p list is 4-1-3-6-12-8-7-NULL
o/p list  4-6-12-8-1-3-7-NULL

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] BST

2011-06-29 Thread Nishant Mittal
how to find kth smallest element in BST...

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Explain the o/p

2011-06-29 Thread Nishant
in 1st printf no. of characters written are 3 and 4 and 3  4
is 0 which is equal to i
next 3 printf are easy...
now in last printf no. of characters written by 2 printf(s) are 3 and
3 and 3  3 is 3 which is printed by outer printf

On Jun 29, 7:40 pm, ashwini singh asingh...@gmail.com wrote:
 please ex-plain the o/p of each line

 o/p is
 2 23 2
 0
 3
 2 2 2 23 2
 3

 #includestdio.h
 #includeconio.h

 main()
 {
        int i;
        i=printf(%d %d,2,2)  printf(%d %d ,3,2);
        printf(\n%d,i);
        printf(\n%d\n,3,4);
        printf(%d %d ,2,2);
        printf(\n%d,printf(%d %d,2,2)  printf(%d %d,3,2));
        getch();

       }

 --
 with regards,
 Ashwini kumar singh
 ECE Final yr.
 MNNIT Allahabad
 *Mobile: *7505519402

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: linked list

2011-06-29 Thread Nishant
@sunny oh... i cudnt understand.can u plz explain by an example

On Jun 29, 7:58 pm, sunny agrawal sunny816.i...@gmail.com wrote:
 I am not using extra space as i am not allocating new memory for storing
 Nodes
 i m using just 2 pointers on the same list, i think that will be allowed



 On Wed, Jun 29, 2011 at 8:18 PM, Nishant mittal.nishan...@gmail.com wrote:
  @sunny plz tell me the solution without using extra list...i've solved
  it using extra list...

  On Jun 29, 7:38 pm, sunny agrawal sunny816.i...@gmail.com wrote:
   maintain two pointers one at the tail of even number list one at tail of
  odd
   Number list
   traverse the list and add the number at required list

   On Wed, Jun 29, 2011 at 8:04 PM, Nishant Mittal
   mittal.nishan...@gmail.comwrote:

segregate even and odd nodes in a singly linked list.Order of even and
odd numbers must be same...
e.g:-
i/p list is 4-1-3-6-12-8-7-NULL
o/p list  4-6-12-8-1-3-7-NULL

--
You received this message because you are subscribed to the Google
  Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
   http://groups.google.com/group/algogeeks?hl=en.

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

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



[algogeeks] OS

2011-06-27 Thread Nishant Mittal
plz recommend me some good sites for OS interview questions...
Thanx in advance

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread Nishant Mittal
do inorder traversal of tree and store values in an array.
Now find pairs by applying binary search on array..

On 6/27/11, manish kapur manishkapur.n...@gmail.com wrote:


 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] MS question

2011-06-27 Thread Nishant Mittal
WAP to sort an array of character strings on the basis of last
character of each string
eg:- {xxxc , yyya, zzzb} = {yyya , zzzb, xxxc}

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from 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] given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread Nishant Mittal
(for array sorted in ascending order)
take 2 indexes i and j pointing to 1st and last element of the array
respectively...
now if(arr[i]+arr[j] == x)
print(arr[i]);
print(arr[j];
else if(arr[i]+arr[j]x)
j--;
else
i++;

I think this should work...(i've not checked)
correct me if i m wrong


On 6/27/11, ankit sambyal ankitsamb...@gmail.com wrote:
 @Bharath : Cud u plz explain how r u searching the elements in O(n) time?
 Because if we use binary search, it will have O(n*log n )  worst case
 time complexity. One way in which I think it cud be made O(n) is that
 we can use a hash table, with a good hash function apart frm the
 array. And then for each element 'm' in the array, we cud search if
 there is an element (sum - m) in O(1) time by using hash table. Still
 we can't assure O(n) time complexity. Because coming up with a good
 hash function is not easy. Again, hash table takes more space




 On Mon, Jun 27, 2011 at 1:40 AM, Nishant Mittal
 mittal.nishan...@gmail.com wrote:
 do inorder traversal of tree and store values in an array.
 Now find pairs by applying binary search on array..

 On 6/27/11, manish kapur manishkapur.n...@gmail.com wrote:


 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] strings

2011-06-22 Thread Nishant Mittal
@Harshal... ur solution is nt correct.it is nt printing the
characters in order as given in i/p...
i know the solution using auxiliary array and using an extra character
array to hold the o/p string but if any1 knows inplace solution then
plz rply...
On 6/22/11, Harshal hc4...@gmail.com wrote:
 You can make use of an auxiliary array(initialized to 0) to store the count
 of each char and then print it that many times.
  char inp[]=abcdaabcdefe;
  int buff[256]={0};

  for(int i=0;istrlen(inp);i++)
   buff[inp[i]]++;

  for(int j=0;j256;j++)
   while(buff[j]--) cout(char)j;

 On Wed, Jun 22, 2011 at 10:27 AM, Sriganesh Krishnan
 2448...@gmail.comwrote:

 Input will be a string. We need to o/p a string with the order of
 characters same as the input but with same characters grouped together.
 I/P: abcdacde
 O/P: aabccdde

 I/P: kapilrajadurga
 O/P: kpilrrjdug

 I/P: 1232
 O/P: 1223 …….. O(n) time……….. O(1) space….


 how can you approach these type of string related problems, is there any
 specific technique involved?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Harshal Choudhary,
 Final Year B.Tech CSE,
 NIT Surathkal, Karnataka, India.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from 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] OS

2011-06-19 Thread Nishant Mittal
It does *not* prevent deadlock so i think (D) is definitely true.

On Sun, Jun 19, 2011 at 5:15 PM, Akshata Sharma
akshatasharm...@gmail.comwrote:

 Two processes, P1 and P2, need to access a critical section of code.
 Consider the following synchronization construct used by the processes:

 /* P1 */
 while (true) {
   wants1 = true;
   while (wants2==true);
 /* Critical Section */
   wants1=false;
 }
 /* Remainder section */

 /* P2 */
 while (true) {
 wants2 = true;
 while (wants1==true);
 /* Critical Section */
 Wants2=false;
 }
 /* Remainder section */

 Here, wants1 and wants2 are shared variables, which are initialized to
 false. Which one of the following statements is TRUE about the above
 construct?
 (A) It does not ensure mutual exclusion.
 (B) It does not ensure bounded waiting.
 (C) It requires that processes enter the critical section in strict
 alternation.
 (D) It does not prevent deadlocks, but ensures mutual exclusion.

 I think B,C are true. It also prevents deadlock so D is also true, not sure
 though. Am I right?

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Explain the o/p

2011-06-15 Thread Nishant Mittal
//Prog 1
#includestdio.h
int main()
{
float a=75.7;
printf(%.10f\n,a); //prints 75.669482
if(75.7a)
printf(Hi);
else
printf(Hello);
return 0;
}

//Prog 2
#includestdio.h
int main()
{
float a=275.7;
printf(%.10f\n,a);//prints 275.7000122070 *WHY???*
if(275.7a)
printf(Hi);
else
printf(Hello);
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.



[algogeeks] Re: C OUTPUT

2011-05-22 Thread Nishant
conversion frm int to float and float to int is very poor in case of
printf funtion
so when we give the input to t then that value is displayed for all
the printf function
since %f modifier doesn't accept x (int) as
a successful argument so it takes the
latest float value..


On May 22, 2:41 pm, sourabh jakhar sourabhjak...@gmail.com wrote:
 #includestdio.h
 void main()
 {
     long x;
     float t;
     scanf(%f,t);
     printf(%d\n,t);
     x=90;
     printf(%f\n,x);
     {
         x=1;
         printf(%f\n,x);
         {
             x=30;
             printf(%f\n,x);
         }
         printf(%f\n,x);
     }
         x==9;
         printf(%f\n,x);

 }

 CAN ANYBODY EXPLAIN THE OUTPUT

 --
 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] Print Hello infinite..................

2011-03-09 Thread Nishant Agarwal
#includestdio.h
void print1();
void print2()
{
printf(Hello\n);
print1();
}
void print1()
{
printf(Hello\n);
print2();
}
int main()
{
print1();
}


On Thu, Mar 10, 2011 at 11:47 AM, nidhi jain nidhi.jain311...@gmail.comwrote:



 @abhishek:isn't it recursion?

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Explain the o/p

2011-03-04 Thread Nishant Agarwal
#includestdio.h
main()
{
long x;
float t;
scanf(%f,t);
printf(%d\n,t);
x=90;
printf(%f\n,x);
{
x=1;
printf(%f\n,x);
{
x=30;
printf(%f\n,x);
}
printf(%f\n,x);
}
x==9;
printf(%f\n,x);

}

o/p on gcc compiler
20.3   (i/p given)
-1073741824
20.299988
20.299988
20.299988
20.299988
20.299988

plz explain the o/p

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: printing without loop

2011-03-01 Thread Nishant Agarwal
use recursion.

On Tue, Mar 1, 2011 at 5:13 PM, bittu shashank7andr...@gmail.com wrote:

 here we go

 void main()
 {
 int i;

 i=1;

 loop:
 printf(%d, i)
 (i100)? i++: return 0;
 go to loop;

 }

 Thanks  Regards
 Shashank Mani  The Best Way to Escape From The Problem is to Solve
 it

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: arrays

2010-09-28 Thread Nishant Agarwal
#includestdio.h
#includestdlib.h
int main()
{
int a[20],i,n,max,t,j,k;
printf(Enter the no. of elements\n);
scanf(%d,n);
for(i=0;in;i++)
scanf(%d,a[i]);
for(i=0;in-1;i++)
{
j=n-1;
max=0;
k=i;
while(ij)
{
if(a[j]a[i]a[j]=max)
{
max=a[j];
k=j;
j--;
}
else
j--;
}
t=a[i];
a[i]=a[k];
a[k]=t;
}
for(i=0;in;i++)
printf(%d\t,a[i]);
return 0;
}

On Tue, Sep 28, 2010 at 3:43 AM, Chi c...@linuxdna.com wrote:

 Move-To-The-Front.

 On Sep 27, 11:58 pm, Anand anandut2...@gmail.com wrote:
   Given an array of integers, for each index i, you have to swap the value
 at
  i with the first value smaller than A[ i ] that comes after index i

 --
 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] Re: Number problem

2010-09-25 Thread Nishant Agarwal
@yellow
your code turns 1000,100,10,2270,12130 to 1,1,1,27,123 repectively
simply it removes all trailing zeros ...

On Wed, Sep 22, 2010 at 8:10 PM, Yellow Sapphire pukhraj7...@gmail.comwrote:

 My Solution.

 Almost same as above but the flag is set by using bits.

 #define SETFLAG(flag, pos) (flag=flag | (1pos-1))
 #define IS_FLAG_SET(flag,pos) (flag  (1pos-1))

 int remove_dup(int n)
 {
int temp=0, temp2=0;
unsigned int flag=0;

/*
 * Reverse the number
 */
while (n0  (temp=temp*10 + n%10), n=n/10);

/*
 * Find duplicates by setting the bits in the flag
 */
n=temp;
temp=0;
while (n0) {
temp2=n%10;
if(!IS_FLAG_SET(flag, temp2)) {
temp=temp*10 + temp2;
SETFLAG(flag, temp2);
}
n=n/10;
}
return temp;
 }

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




-- 
 :-)
*
Nishant Agarwal
Computer Science and Engineering
NIT 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] Re: Number problem

2010-09-25 Thread Nishant Agarwal
Here's the code
int rem_dup(int n)
{
int *a,i,c,t,d,count[10]={0},arr[20],j=0,sum=0;
a=(int *)malloc(sizeof(a));
for(i=0;n0;i++)//storing each digit of number in an array
{
a[i]=n%10;
n=n/10;
}
c=d=i-1;
i=0;
while(ic)//reversing the array
{
t=a[i];
a[i++]=a[c];
a[c--]=t;
}
for(i=0;i=d;i++)//setting repeated digits to -1
{if(count[a[i]]==0)
count[a[i]]++;
else
a[i]=-1;
}
for(i=0,j=0;i=d;i++)  //storing all non repeating digits in anothor
array arr[]
{
if(a[i]!=-1)
{
arr[j]=a[i];
j++;
}
}
for(i=0;ij;i++)
sum=sum+arr[i]*power(10,j-i-1);
  return sum;
}

On Thu, Sep 23, 2010 at 12:39 AM, Dave dave_and_da...@juno.com wrote:

 @Saurabh: Doesn't this turn 10 into 1? You need to count the digits in
 the number as you are reversing it, and replace the second while loop
 with a for loop with that many iterations.

 Dave

 On Sep 21, 11:28 pm, saurabh agrawal saurabh...@gmail.com wrote:
  @dave:
  your code is producing 4526 for input=24526 instead of 2456
  Here's corrected code :)
  /CODE///
  int function(int n){
  int a[10]={0},temp=0,result =0;
  while(n){   //reverse the number..
   temp=10*temp+n%10;
   n/=10;
  }
  n=temp;
  while(n){   ///remove duplicate digits...
   if(a[n%10]==0){
   a[n%10]=1;
   result=10*result+n%10;
   }
  n/=10;
  }
  return result;}
 
  ///END/
 
 
 
  On Wed, Sep 22, 2010 at 8:51 AM, Dave dave_and_da...@juno.com wrote:
   @Saurabh: Doesn't your code turn 123 into 321? Try this:
 
   int function(int n)
   {
  int a[10]={0};
  int result=0;
   int place=1;
   while(n){
  if(a[n%10]==0){
  a[n%10]=1;
   result+=(n%10)*place;
  place*=10;
  }
  n/=10;
  }
  return result;
   }
 
   Dave
 
   On Sep 21, 3:12 pm, saurabh agrawal saurabh...@gmail.com wrote:
int function(int n){
 
int a[10]={0};
int result =0;
while(n){
if(a[n%10]==0){
a[n%10]=1;
result=10*result+n%10;
}
n/=10;}
 
return result;`
 
}
On Wed, Sep 22, 2010 at 12:39 AM, Albert alberttheb...@gmail.com
   wrote:
 Given a number find the number by eliminating the duplicate digits
 in
 the number..
 
 for eg:   24526  ans is 2456
 .
 
 int function(int n)
 {
 
  .
  .
  .
 
 }
 
 Give all sort of solutions to this problem.
 
 Efficiency in the code is important 
 
 --
 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
 algogeeks%2bunsubscr...@googlegroups­.com
   algogeeks%2bunsubscr...@googlegroups­.com
 .
 For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.-Hide quoted text -
 
- Show quoted text -
 
   --
   You received this message because you are subscribed to the Google
 Groups
   Algorithm Geeks group.
   To post to this group, send email to algoge...@googlegroups.com.
   To unsubscribe from this group, send email to
   algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 algogeeks%2bunsubscr...@googlegroups­.com
   .
   For more options, visit this group at
  http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text -
 
  - Show quoted text -

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to 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.




-- 
 :-)
*
Nishant Agarwal
Computer Science and Engineering
NIT 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.



  1   2   >