Re: [algogeeks] Find longest consecutive subsequence

2014-01-27 Thread Nishant Pandey
); 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

Re: [algogeeks] DISTINCT Permutations ( Not Easy)

2014-01-07 Thread Nishant Pandey
); 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

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

2013-11-26 Thread Nishant Pandey
...@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

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

2013-11-26 Thread Nishant Pandey
+ 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

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

2013-11-25 Thread Nishant Pandey
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

[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

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,

[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

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

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

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

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

[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

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

Re: [algogeeks] Re: PLease suggest the Algo for this problem

2013-05-23 Thread Nishant Pandey
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

[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

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

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

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

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

[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

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

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

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

Re: [algogeeks] Re: Amazon Interview Questions

2013-03-12 Thread Nishant Pandey
-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

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

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

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

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

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 .

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

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

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

[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

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

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

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++) {

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

2012-07-04 Thread Nishant Pandey
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

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

[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

Re: [algogeeks] Inorder Iterative code for printing paths

2012-06-28 Thread Nishant Pandey
(); stack_temp.pop(); i--; //if(current-right) //coutcurrent-dataendl; current=current-right; if(current) i++; } } } } -- Cheers, Nishant Pandey |Specialist Tools

[algogeeks] Inorder Iterative code for printing paths

2012-06-25 Thread Nishant Pandey
) //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

Re: [algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread Nishant Pandey
://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

Re: [algogeeks] Re: Microsoft Interview Question

2012-06-21 Thread Nishant Pandey
to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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

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

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

2012-06-19 Thread Nishant Pandey
...@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

Re: [algogeeks] Can anyone plz explain how we get this output

2012-06-14 Thread Nishant Pandey
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

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
://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

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from 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

Re: [algogeeks] MS Question: Reverse stack using push, pop without any auxiliary data structure

2012-06-14 Thread Nishant Pandey
/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

Re: [algogeeks] Adobe interiew question

2012-06-13 Thread Nishant Pandey
. To unsubscribe from 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

Re: [algogeeks] [amazon]: dutch national flag algorithm

2012-06-10 Thread Nishant Pandey
/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

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Nishant Pandey
://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

Re: [algogeeks] first Repeating character in a string

2012-06-08 Thread Nishant Pandey
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

Re: [algogeeks] Simple Question ,Find Error

2012-06-04 Thread Nishant Pandey
://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

Re: [algogeeks] LINKED LIST QUESTION

2012-06-04 Thread Nishant Pandey
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

Re: [algogeeks] Linked list using void pointer

2012-05-31 Thread Nishant Pandey
+ 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

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

Re: [algogeeks] Linked list using void pointer

2012-05-31 Thread Nishant Pandey
, 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