Re: [algogeeks] Re: Fwd: SORTING ARRAYS

2011-07-26 Thread ankit sambyal
Following is the working code :Time complexity : O(n^2) Space complexity : O(1) void swap(int *a,int *b) { int temp; temp=*a; *a=*b; *b=temp; } /*num is the number which is searched in the array arr[]. index is the index in the array arr[] by which the searched number is to b

Re: [algogeeks] direct i

2011-07-26 Thread salvador_cerinza
Let say stack S. 1.insert elements in S of A[] from right to left. 2.int val = S.top(); 3.S.pop(); 4.now check val with S.top() until u find any element smaller than val. 5.Note down the element pop it from stack 6.if step 4 is true , the push val in stack S and all elements which were popped in th

Re: [algogeeks] direct i

2011-07-26 Thread Pankaj
Can you please elaborate a little about your stack based solution. I was thinking of using queue but was unable to make a perfect algo. On Wed, Jul 27, 2011 at 12:18 PM, salvador_cerinza < vishwakarma.ii...@gmail.com> wrote: > i m suggesting stack not just for best case only . > > > On Wed, Jul

Re: [algogeeks] direct i

2011-07-26 Thread salvador_cerinza
i m suggesting stack not just for best case only . On Wed, Jul 27, 2011 at 12:16 PM, Pankaj wrote: > Even in array best case can be O(n). Why use stack? > On Wed, Jul 27, 2011 at 12:14 PM, salvador_cerinza < > vishwakarma.ii...@gmail.com> wrote: > >> Best case : O(n) >> Worst case : O(n^2) >>

Re: [algogeeks] direct i

2011-07-26 Thread Pankaj
Even in array best case can be O(n). Why use stack? On Wed, Jul 27, 2011 at 12:14 PM, salvador_cerinza < vishwakarma.ii...@gmail.com> wrote: > Best case : O(n) > Worst case : O(n^2) > can be done using stack. > > Thinking of better solution. . > > > On Wed, Jul 27, 2011 at 11:50 AM, ankit sambyal

Re: [algogeeks] direct i

2011-07-26 Thread salvador_cerinza
Best case : O(n) Worst case : O(n^2) can be done using stack. Thinking of better solution. . On Wed, Jul 27, 2011 at 11:50 AM, ankit sambyal wrote: > O(n^2) algo is trivial. Can anybody think of a better approach ??? > > -- > You received this message because you are subscribed to the Google Gro

[algogeeks] Re: MS interview:

2011-07-26 Thread geek forgeek
anyone?? On Tue, Jul 26, 2011 at 11:36 PM, geek forgeek wrote: > Function to display the directory structure in a user friendly way taking > root dir as arg > for a general OS. You may assume and state some basic APIs available in > that OS > -- You received this message because you are subscri

Re: [algogeeks] Re: Lucky numbers

2011-07-26 Thread sunny agrawal
As we start every time from the beginning, so 1 will never be deleted hence in last it will remain there I faced the same Question in MS Written where question was..Given a number find if the number is Lucky or not? that can be easily found because every time we remove the numbers at even indexes

[algogeeks] MS interview:

2011-07-26 Thread geek forgeek
Function to display the directory structure in a user friendly way taking root dir as arg for a general OS. You may assume and state some basic APIs available in that OS -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, s

Re: [algogeeks] Re: Amazon Question

2011-07-26 Thread sunny agrawal
@shiva viknesh this is a different Question... @saurabh how is nlgn possible, total no of possible substrings are n^2 this is the O(n^2) solutionOn Wed, Jul 27, 2011 at 8:09 AM, saurabh singh for(int l = 0; l < len; l++){                 for(int i = 0; i < len-l; i++){                      

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread Rajeev Kumar
Hey ankit, i gave java code also...didn't u check it in the link...anyway i am explaining here. *Note : Position count starts from 0. * *ex: {1,2,3,4} ...position of '1' is zero* * * *In the below approach,we are checking element position in the modified list(after deletion ope

Re: [algogeeks] Re: Fwd: SORTING ARRAYS

2011-07-26 Thread Anand Saha
I don't think so. Try it on {2, 5, 1, 7} and {5, 7, 1, 2} -- On Wed, Jul 27, 2011 at 10:33 AM, Sonal Maheshwari wrote: > i think the following shud work: > > i=j=0; > while(i< n && j { > if ( a[i] < b[j] ) > { > pos= find(b, a[i]); ///find the position of a[i] in > ar

Re: [algogeeks] direct i

2011-07-26 Thread ankit sambyal
O(n^2) algo is trivial. Can anybody think of a better approach ??? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsub

[algogeeks] Re: Fwd: SORTING ARRAYS

2011-07-26 Thread Sonal Maheshwari
i think the following shud work: i=j=0; while(i< n && j b[j] ) { pos= find(a, b[j]); ///find the position of b[j] in array a swap ( a[i], a[pos] ); //swapping the two numbers } i++; j++; } Correct me if m wrong... On Jul 27, 8:46 am, siva

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread Rajeev Kumar
@ankit : can u give me a case where it fails... On Wed, Jul 27, 2011 at 8:33 AM, ankit sambyal wrote: > @rajeev:ur algo does not give the correct answer. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send ema

Re: [algogeeks] Re: Fwd: SORTING ARRAYS

2011-07-26 Thread subramania jeeva
This problem is termed as nut and bolts problem..:) We've to use a modification of quick sort..:) Cheers ~ Jeeva ~ On Wed, Jul 27, 2011 at 9:16 AM, siva viknesh wrote: > Given two arrays > a[] = {1,3,2,4} > b[] = {4,2,3,1} > both will have the same numbers but in different combi

[algogeeks] direct i

2011-07-26 Thread siva viknesh
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 for example array A = {3,7,4,9,10,2,1} The Output array should be : 2 4 3 7 9 1 10 -- You received this message because you are subscribed to the Goog

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread Rajeev Kumar
@ankit : can u give me a case where it fails... On Wed, Jul 27, 2011 at 8:33 AM, ankit sambyal wrote: > @rajeev:ur algo does not give the correct answer. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send ema

Re: [algogeeks] rotate a matrix NVIDIA question

2011-07-26 Thread Puneet Gautam
Let k=no. of rows If k=odd mirror the matrix about the ((k/2)+1) th row.. else start from k/2 and (k/2 +1 )th row, swap the two rows.. then k/2-1 and k/2 +2 and swap and soon... OR maintain array as a pointer table.. keep on changing the base address to which a[i points to.. Let *a[]={{1,1,0},

[algogeeks] Re: Redundant parentheses

2011-07-26 Thread bharath
I think I figured out a solution. Please correct me if I missed anything. *Example:* Input: ((A+B)*C) Expected output: (A+B)*C *Assumptions:* - Peek (queue) just tells the element in front end of queue without deleting it. - precedence( ) is a function which looks a precedence table of operator

[algogeeks] Re: Lucky numbers

2011-07-26 Thread bharath
This is the extended Josephus problem. More details and solution formulation here: http://www.cs.man.ac.uk/~shamsbaa/Josephus.pdf On Jul 26, 11:04 pm, Nikhil Gupta wrote: > Please suggest a good algo for this : > > You have numbers 1 to n (consider them arranged in a circular order) > Then start

[algogeeks] rotate a matrix NVIDIA question

2011-07-26 Thread Deoki Nandan
rotate a 2D matrix by angle 180 -- **With Regards Deoki Nandan Vishwakarma * * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Lucky numbers

2011-07-26 Thread Nikhil Gupta
Please suggest a good algo for this : You have numbers 1 to n (consider them arranged in a circular order) Then starting from the first number, all alternate numbers are deleted. Once the entire range is traversed with this procedure, the same is performed from the beginning again (as they are cir

Re: [algogeeks] AMAZON Q

2011-07-26 Thread Anand Saha
Construct a BST using ar[], where each node contains the ar index information as well (in addition to the value). Now iterating through ar. For each element, traverse the BST by value, counting only those nodes where the value AND index# are greater then self. Once done traversal, update ar_low. -

[algogeeks] Re: Fwd: SORTING ARRAYS

2011-07-26 Thread siva viknesh
Given two arrays a[] = {1,3,2,4} b[] = {4,2,3,1} both will have the same numbers but in different combination. We have to sort them . The condition is that you cannot compare only elements within the same array.You can compare element of one array with another only. On Jul 27, 8:45 am, sivaviknesh

[algogeeks] Fwd: SORTING ARRAYS

2011-07-26 Thread sivaviknesh s
-- Forwarded message -- From: Padmaja Sridharan Date: Wed, Jul 27, 2011 at 5:15 AM Subject: SORTING ARRAYS To: mitcse08i...@googlegroups.com Given two arrays a[] = {1,3,2,4} b[] = {4,2,3,1} both will have the same numbers but in different combination. We have to sort them . The

[algogeeks] Re: AMAZON Q

2011-07-26 Thread bharath
Oops, my bad. I missed that lowest in a[i+1...n] part. On Jul 26, 10:17 pm, ankit sambyal wrote: > @bharath :I think array C is not the resultant array. Take an example and > explain -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To po

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread ankit sambyal
@bharath :I think array C is not the resultant array. Take an example and explain -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread ankit sambyal
@rajeev:ur algo does not give the correct answer. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegrou

[algogeeks] Re: AMAZON Q

2011-07-26 Thread bharath
We can use "count sort" to solve this. Assuming each element is the array is in range 1-k (k=O(n)). for (i=0 to n) C[A[i]]=C[A[i]]+1 for (i=1 to k) C[i]=C[i]+C[i-1] Array 'C' will have the resultant array. On Jul 26, 9:20 pm, Rajeev Kumar wrote: > * > Algorithm : > 1)Conside original array

[algogeeks] Re: Redundant parentheses

2011-07-26 Thread bharath
Well, the answer should still be in infix except without 'redundant' parantheses. So, just converting it to prefix/postfix will not do. If we were to scan the array and remove parentheses, you might end up deleting relevant ones. Eg: ((A+B)*C) should output (A+B)*C. So, the key point here is t

Re: [algogeeks] Re: Amazon Question

2011-07-26 Thread saurabh singh
using suffix tree this can be done in o(nlogn) though will take extra space. On Wed, Jul 27, 2011 at 12:47 AM, siva viknesh wrote: > http://geeksforgeeks.org/?p=767 > > On Jul 26, 11:49 pm, Pratz mary wrote: > > how? > > > > On 26 July 2011 23:18, ankit sambyal wrote: > > > > > @vivin : Suffix

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread Rajeev Kumar
* Algorithm : 1)Conside original array a[] 2)Construct a sorted list with the array elements(O(nlogn)) 3)Traverse across all elements of the original array 'a' and find it's position(right occurence) in the sorted list using binary search. -position in the sorted list returns the number of elemen

[algogeeks] Re: Redundant parentheses

2011-07-26 Thread Poised~
To get rid of all parenthesis, we use prefix or postfix notation. But if you simply want to remove the parenthesis, why not simply scan and remove the parenthesis by shifts OR by storing the non-parenthesis elements in another output array as we scan the elements? If I am wrong in getting the qu

Re: [algogeeks]

2011-07-26 Thread Poised~
Kavitha, >From a sorted array you need to find two elements whose sum is equal to the value given by user. -- 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/-

Re: [algogeeks]

2011-07-26 Thread Poised~
Niks, This is the efficient solution for a sorted array. This algo doesn't use any other storage and is completed in one scan of array only. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://g

Re: [algogeeks] Re: Nagarro Coding Round Ques......

2011-07-26 Thread SkRiPt KiDdIe
I dint get wat are you speaking of.each alphabet is mapped onto ascii_val-'a' ie ascii of a=97. now check for odd and even occurence is performed. Work it on paper u'll get it. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this g

Re: [algogeeks] Re: please help

2011-07-26 Thread SkRiPt KiDdIe
#include #include #include #include using namespace std; #define ll long long int #define INF 0x7fff ll mask(ll x,string str,ll dist) { ll re=INF,y=0,len; len=str.size(); for(int i=0;ire )continue; else if((int)str[(i+dist)%len]>str;//60 len strings len=str

Re: [algogeeks] Re: please help

2011-07-26 Thread SkRiPt KiDdIe
#include #include #include #include using namespace std; #define ll long long int #define INF 0x7fff ll mask(ll x,string str,ll dist) { ll re=INF,y=0,len; len=str.size(); for(int i=0;ire )continue; else if((int)str[(i+dist)%len]>str;//60 len strings len=str.size();

Re: [algogeeks] Re: please help

2011-07-26 Thread SkRiPt KiDdIe
#include #include #include #include using namespace std; #define ll long long int #define INF 0x7fff ll mask(ll x,string str,ll dist) { ll re=INF,y=0,len; len=str.size(); for(int i=0;ire )continue; else if((int)str[(i+dist)%len]>str;//60 len strings len=str.size();

Re: [algogeeks] Re: please help

2011-07-26 Thread SkRiPt KiDdIe
#include #include #include #include using namespace std; #define ll long long int #define INF 0x7fff int mask(ll x,string str,ll dist) { ll re=INF,y=0,len; len=str.size(); for(int i=0;ire )continue; else if((int)str[(i+dist)%len]>str;//60 len strings len=str.size()

Re: [algogeeks] Re: Nagarro Coding Round Ques......

2011-07-26 Thread Pratz mary
hey the above case wont work for a few casesfor instance wen the seventh letter of the alphabet is involved... On 26 July 2011 15:32, sachet wrote: > please explainthe code > #include > using namespace std; > int main() > { > int x=0; > string str; > cin>>str;//only lowercase > for(int i

Re: [algogeeks] plzz explain

2011-07-26 Thread Piyush Sinha
http://www.cprogramming.com/tutorial/size_of_class_object.html On 7/27/11, TUSHAR wrote: > 1. > #include > using namespace std; > class abc > { > int x; > static int y; > }; > main() > { > abc a; > cout< cout< } > > why o/p is 4 4 ??? > > >

Re: [algogeeks] C output.

2011-07-26 Thread Anurag Narain
@Someshwar: precedence of && > || http://www.difranco.net/cop2220/op-prec.htm -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to alg

[algogeeks] Re: Redundant parentheses

2011-07-26 Thread bharath
Ah! a good friend just pointed out that step (2) is not quite simple. A postfix expression bases precedence by the operator position due to lack of parentheses. I am not sure about the code to convert from postfix to infix. It *has* to insert parentheses generously to add to the precedence informat

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

2011-07-26 Thread sivaviknesh s
we can do like creating an adjacency matrix..populate all values i.e. cost to reach each node...finally find the nodes that has min value...any other gud solutions?? On Wed, Jul 27, 2011 at 2:16 AM, sivaviknesh s wrote: > the question is clear..you draw the sample test case and work out .. >

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

2011-07-26 Thread sivaviknesh s
the question is clear..you draw the sample test case and work out .. you will understand 1 / / \ 4 2 3 /\ 5 6 here from node 2 the maximum cost to reach any node 'i' is 2 and minimum is 1 ...so M(2) = max(1,2)=2..the same is the case

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

2011-07-26 Thread siva viknesh
-- Forwarded message -- From: jayapriya surendran Date: Sep 29 2010, 9:41 pm Subject: Directi question-centre of the tree To: Algorithm Geeks In graph theory, atreeis defined as a graph on N nodes,and (N-1) un-directed edges such that there are no cycles in the graph.Each node

Re: [algogeeks] preprocessor directives

2011-07-26 Thread Naveen Agrawal
I think "k" value will depend on compiler as we have changed "i" value in the expression "k = ++i*++i" and used it again in the same expression. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@g

[algogeeks] Redundant parentheses

2011-07-26 Thread bharath
Given an expression (A+(B*C)), remove redundant parentheses. Output in this case should be A+B*C. My initial solution: (1) Convert expression from infix to postfix (or prefix) [This way, all parentheses are removed] (2) Now, convert postfix (or prefix) expression back to infix. Is there a better w

Re: [algogeeks] Re: write an scanf that reads only a to z charchter.............

2011-07-26 Thread Tushar Kanta Rath
thanks to all . :) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more op

[algogeeks] plzz explain

2011-07-26 Thread TUSHAR
1. #include using namespace std; class abc { int x; static int y; }; main() { abc a; cout

Re: [algogeeks] Re: please help

2011-07-26 Thread coder coder
thanx bro -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this gro

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
@coder :Got my mistake. There is a slight change in the checkmin function. Actually I was returning the modified value of i and j. Following is the correct code : #include using namespace std; int checkmin(char arr[],int size,int i,int j) { int k=0,*m=i,n=j*; while(arr[i]==arr[j] && khttp://

Re: [algogeeks] Re: write an scanf that reads only a to z charchter.............

2011-07-26 Thread rajeev bharshetty
@Nithish Yup you are right :) On Wed, Jul 27, 2011 at 12:54 AM, Nitish Garg wrote: > scanf("%[^a-z]",z); will only accept characters other than a-z. > The solution must be scanf("%[a-z]", z); to read only the characters a-z. > > -- > You received this message because you are subscribed to the Goo

Re: [algogeeks] Re: please help

2011-07-26 Thread aditi garg
can u plz explain dis code? On Wed, Jul 27, 2011 at 12:37 AM, coder coder wrote: > the answer should be 6 correct me if i am getting the question wrong > > > #include > using namespace std; > > > int checkmin(char arr[],int size,int i,int j) > { >int k=0; > > while(arr[i]==arr[j] && k{

[algogeeks] Re: write an scanf that reads only a to z charchter.............

2011-07-26 Thread Nitish Garg
scanf("%[^a-z]",z); will only accept characters other than a-z. The solution must be scanf("%[a-z]", z); to read only the characters a-z. -- 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

[algogeeks] Re: Amazon Question

2011-07-26 Thread siva viknesh
http://geeksforgeeks.org/?p=767 On Jul 26, 11:49 pm, Pratz mary wrote: > how? > > On 26 July 2011 23:18, ankit sambyal wrote: > > > @vivin : Suffix trees are memory intensive.. > > > This problem can be solved just by running 2 nested loops in O(1) > > space and O(n^2) time > > > -- > > You rece

[algogeeks] Re: write an scanf that reads only a to z charchter.............

2011-07-26 Thread rShetty
scanf("%[^a-z]",z); On Jul 27, 12:13 am, TUSHAR wrote: > write an scanf that reads only a to z charchter. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubs

Re: [algogeeks] write an scanf that reads only a to z charchter.............

2011-07-26 Thread rajeev bharshetty
scanf("%[^a-z]",i); On Wed, Jul 27, 2011 at 12:43 AM, TUSHAR wrote: > write an scanf that reads only a to z charchter. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@google

[algogeeks] write an scanf that reads only a to z charchter.............

2011-07-26 Thread TUSHAR
write an scanf that reads only a to z charchter. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...

Re: [algogeeks] Re: please help

2011-07-26 Thread coder coder
the answer should be 6 correct me if i am getting the question wrong #include using namespace std; int checkmin(char arr[],int size,int i,int j) { int k=0; while(arr[i]==arr[j] && khttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
@coder : No, my solution gives the correct answer. Check it out 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

Re: [algogeeks] Re: please help

2011-07-26 Thread coder coder
@ankit still your solution is not giving the correct result for this test 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 alg

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
@coder: my mistake. There is a typo in my code. the condition is : while(arr[i]==arr[j] && khttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Re: please help

2011-07-26 Thread coder coder
ankit your solution gives answer 11 for test case ABCDEAABCCDA ie AABCDEAABCCD Isn't solution is AABCCDAABCDE ie 6 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
There is a mistake in my code: In the function int checkmin(char arr[],int size,int i,int j) after the while loop in the line if(k==0) It shud be : if(k==size) instead of if(k==0) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to t

Re: [algogeeks] Re: please help

2011-07-26 Thread coder coder
@ankit your answer is wrong for the test case ABCDEAABCCDA -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@

[algogeeks] Re: please help

2011-07-26 Thread coder coder
yes -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at

Re: [algogeeks] Re: Amazon Question

2011-07-26 Thread Pratz mary
how? On 26 July 2011 23:18, ankit sambyal wrote: > @vivin : Suffix trees are memory intensive.. > > This problem can be solved just by running 2 nested loops in O(1) > space and O(n^2) time > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" gr

[algogeeks] Strings

2011-07-26 Thread syl
im having problem with learning suffix array i have few doubts can kmp be an alternative to suffix array in every case i tried to read SA from wiki but they didnt explain much... could anyone help me in this...i want to learn how to implement it and where to use it. -- You recei

Re: [algogeeks] Re: please help

2011-07-26 Thread ankit sambyal
int getFirstIndexInLex(char arr[],int size) { int minindex=0,i; for(i=1;ihttp://groups.google.com/group/algogeeks?hl=en.

Re: [algogeeks] Re: please help

2011-07-26 Thread Pratz mary
would it make a difference if it wasnt a circular array? On 26 July 2011 23:52, coder coder wrote: > in the circular array ABCDEABCCDE > The answer is 6 because the circular string starting from the element > A in the 6th position comes first in the dictionary formed from all > the possible str

Re: [algogeeks] Re: please help

2011-07-26 Thread Ankur Khurana
i believe you are asking for rank in lexicographic rotation On Tue, Jul 26, 2011 at 11:52 PM, coder coder wrote: > in the circular array ABCDEABCCDE > The answer is 6 because the circular string starting from the element > A in the 6th position comes first in the dictionary formed from all > the

[algogeeks] Re: please help

2011-07-26 Thread coder coder
in the circular array ABCDEABCCDE The answer is 6 because the circular string starting from the element A in the 6th position comes first in the dictionary formed from all the possible strings of the circular array. for "ABCDEAABCCDA" is 6 -- You received this message because you are subscribed

Re: [algogeeks] please help

2011-07-26 Thread sukhmeet singh
provide a sample i/p output..!! On Tue, Jul 26, 2011 at 11:43 PM, coder coder wrote: > Write a program to find the index in an circular array such that the > string that is formed starting from that index is first in > lexicographic order. > > on all the sites the code part is misunderstood for t

[algogeeks] please help

2011-07-26 Thread coder coder
Write a program to find the index in an circular array such that the string that is formed starting from that index is first in lexicographic order. on all the sites the code part is misunderstood for the test case "ABCDEAABCCDA" -- You received this message because you are subscribed to the Goo

Re: [algogeeks] Re: AMAZON Q

2011-07-26 Thread ankit sambyal
@vivin : Your algo seems to be wrong. Plz take an example and explain. I may hv misunderstood u .. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this grou

[algogeeks] Re: C Output

2011-07-26 Thread siva viknesh
ideone.com is also great On Jul 26, 10:03 pm, Ram CEG wrote: > ya it would ignore \ alone.. > > On Tue, Jul 26, 2011 at 10:27 PM, aditi garg wrote: > > > > > > > > > ya thats wat my doubt was...if its not a recognised escape sequence thn how > > is it interpreted?? > > Would the compiler jst igno

[algogeeks] Re: MS c output ques

2011-07-26 Thread siva viknesh
@both...fantastic explanation...thanks :) On Jul 26, 10:34 pm, rajeev bharshetty wrote: > So if the input is gujarat it scans gujarat to find the first character in > gujarat which is also present in india . So the character in gujarat is a so > it will stop on encountering a and prints the s

[algogeeks] Re: AMAZON Q

2011-07-26 Thread vivin
The binary search trees can be used ...arrange the given elements in binary search tree ...search for each element in the tree count the number of nodes along its left successors until the leaf node is reached ...!! thats the ans !! On Jul 26, 6:53 pm, Someshwar Chandrasekaran wrote: > On Tu

Re: [algogeeks] Re: Amazon Question

2011-07-26 Thread ankit sambyal
@vivin : Suffix trees are memory intensive.. This problem can be solved just by running 2 nested loops in O(1) space and O(n^2) 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.

[algogeeks] Re: Amazon Question

2011-07-26 Thread vivin
suffix tree can be used print all the nodes...u ll get every substring ..!! On Jul 26, 8:51 pm, Ankur Garg wrote: > Hey Guys > > Can we use KMP Algorithm here to generate permutations...May be a bit > modification is req > > On Tue, Jul 26, 2011 at 9:07 PM, keyan karthi > wrote: > > > > > >

[algogeeks] IPC Material

2011-07-26 Thread Swathi
Does anyone has good material on InterProcessCommunications? Please share. Thanks in advance. -Swathi -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this

Re: [algogeeks] Facebook Interview question at NIT Warangal

2011-07-26 Thread rajeev bharshetty
@Ankur The link does has a very good explanation. Nice solution :) On Tue, Jul 26, 2011 at 10:47 PM, Kunal Patil wrote: > @Ankur Garg: Nice explanation at the link given by u... > > > On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg wrote: > >> Check this >> >> http://codesam.blogspot.com/2011/03/f

Re: [algogeeks] MS c output ques

2011-07-26 Thread rajeev bharshetty
So if the input is gujarat it scans gujarat to find the first character in gujarat which is also present in india . So the character in gujarat is a so it will stop on encountering a and prints the string scanned till then. If the input is india , it matches at first location so it prints the cont

Re: [algogeeks] MS c output ques

2011-07-26 Thread kc Liyan
if U given input as gujarat the scanf will accept inputs as char's.but there s an ^ which means ex-or operation should be performed regular check of existance of any char of {india}... untill it get's the existance then it will stop the input getting..finally it prints as guj O

Re: [algogeeks] GATE C-Question

2011-07-26 Thread sasi kumar
hi > void XYZ(int a[],int b[], int c[]) > { > int i,j,k; > i=j=k=0; > while((i { > if (a[i]  c[k++]=a[i++]; >  else >  c[k++]=b[j++]; >0 > } In this case either i value or j value is incremented at a time in an iteration . So its impossible that both the conditions (i< n) and (j > Which of

Re: [algogeeks] Facebook Interview question at NIT Warangal

2011-07-26 Thread Kunal Patil
@Ankur Garg: Nice explanation at the link given by u... On Tue, Jul 26, 2011 at 10:35 PM, Ankur Garg wrote: > Check this > > http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html > > > On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki wrote: > >> Here is the working code.. >> >> #i

[algogeeks] MS c output ques

2011-07-26 Thread siva viknesh
main() { char str[80]; strcpy(str,"junk"); scanf("%[^india]",str); printf("%s",str); } ...input is gujarat.output is guj.plz explain how? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to alg

Re: [algogeeks] Facebook Interview question at NIT Warangal

2011-07-26 Thread Ankur Garg
Check this http://codesam.blogspot.com/2011/03/find-all-subsets-of-given-set.html On Tue, Jul 26, 2011 at 9:41 PM, Vishal Thanki wrote: > Here is the working code.. > > #include > #include > int a[] = {1,2,3,4,5}; > #define ARRLEN(a) (sizeof(a)/sizeof(a[0])) > void print_comb(int len) > { >

Re: [algogeeks] C Output

2011-07-26 Thread Ram CEG
ya it would ignore \ alone.. On Tue, Jul 26, 2011 at 10:27 PM, aditi garg wrote: > ya thats wat my doubt was...if its not a recognised escape sequence thn how > is it interpreted?? > Would the compiler jst ignore ''\''? > > > On Tue, Jul 26, 2011 at 10:25 PM, Ram CEG wrote: > >> op:abc.. \c is n

Re: [algogeeks] C Output

2011-07-26 Thread Vivek Srivastava
Yes compiler always ignores the first '\' and if it finds a recognizable character after this escape sequence . it will interpret it. Otherwise it just dumps it according to predefined semantics of machine code generation.But I would suggest everyone in this group to try out http://www.codepad.org

Re: [algogeeks] C Output

2011-07-26 Thread aditi garg
ya thats wat my doubt was...if its not a recognised escape sequence thn how is it interpreted?? Would the compiler jst ignore ''\''? On Tue, Jul 26, 2011 at 10:25 PM, Ram CEG wrote: > op:abc.. \c is not an escape sequence > > > On Tue, Jul 26, 2011 at 10:17 PM, aditi garg wrote: > >> what will b

Re: [algogeeks] C Output

2011-07-26 Thread Ram CEG
op:abc.. \c is not an escape sequence On Tue, Jul 26, 2011 at 10:17 PM, aditi garg wrote: > what will be the output fr this?? > printf("ab\c"); > > > On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul wrote: > >> Dipankar, Thanks!!! >> >> >> On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro wrote: >> >>

Re: [algogeeks] C Output

2011-07-26 Thread aditi garg
what will be the output fr this?? printf("ab\c"); On Tue, Jul 26, 2011 at 6:22 PM, swetha rahul wrote: > Dipankar, Thanks!!! > > > On Tue, Jul 26, 2011 at 8:44 AM, Dipankar Patro wrote: > >> >> Swetha, >> >> '\' in C is used to denote a escape sequence in C strings (and also in >> many other lang

Re: [algogeeks] self referential struct. Contd.

2011-07-26 Thread Nikhil Gupta
Padding is not a topic of self referential structure. Padding means that extra spaces of memory are used by the compiler to allocate memory. This is done to have the memory address as a multiple of the size of the variable. This speeds up the processing of these variables by the compiler. On Tue,

Re: [algogeeks]

2011-07-26 Thread saurabh singh
@kavitha Yeah I was just giving examples.The idea is to push everything into a buffer and then parse according to ur needs.From my experiences and experiments the list in ascending order of time taken is 1,fread_unlocked 2.fread 3getchar_unlocked 4.getchar 5.gets (3,4 & 5 may show variable behavi

Re: [algogeeks] Closest as Possible

2011-07-26 Thread saurabh singh
Is answer 0 ?? On Tue, Jul 26, 2011 at 7:41 PM, rajeev bharshetty wrote: > Sum of any number of elements on the two partitions should be as close as > possible. > > > On Tue, Jul 26, 2011 at 6:49 PM, Puneet Gautam wrote: > >> @rshetty: do u mean the sum of any no of elements separately in the >>

Re: [algogeeks] OUTPUT

2011-07-26 Thread kavitha nk
sry sry o/p ll be 0 1 0in the 2nd printf the value ll be evaluated from rite to left... so in the 1st printf i's vlue ll be 0 and in the 2nd printf stmt rite expression is evaluated first and then i value ll be modified in it.. and with hte help of it left one is evaluated...crct me if i'm wron

  1   2   3   >