Re: [algogeeks] Re: Amazon Interview Question

2013-04-30 Thread Gary Drocella
Counting sort does not run in O(1) space though. Optimally it will run in O(K) space, where A is an array of integer numbers and K = max(A) - min(A) On Saturday, February 9, 2013 9:52:01 PM UTC-5, Mohanabalan wrote: can use counting sort On Sun, Jul 15, 2012 at 6:37 PM, santosh thota

Re: [algogeeks] Re: Amazon Interview Question

2013-04-30 Thread Gary Drocella
A bit vector is basically just a sequence of bits such as a word or even an array of words. Here is an example... int x = 5; // 32 bit word size on Intel IA-32 Architecture In C programming language. A variable in C will be either located in a register in memory or in Main Memory. You

[algogeeks] Re: Amazon Interview Question

2013-04-29 Thread Gary Drocella
This will only work if each element in the array are relatively prime to one another, that is for any two elements x, y in array A the gcd(x,y) = 1, which is also just another way of saying no number divides another number in the array. Once this rule is broken, then the algorithm will no

Re: [algogeeks] Re: Amazon Interview Question

2013-04-29 Thread Parag Khanna
use XOR On Tue, Apr 30, 2013 at 6:12 AM, Gary Drocella gdroc...@gmail.com wrote: This will only work if each element in the array are relatively prime to one another, that is for any two elements x, y in array A the gcd(x,y) = 1, which is also just another way of saying no number divides

Re: [algogeeks] Re: Amazon interview question

2013-04-14 Thread BackBencher
:O the final required sum would be 4C0 * a5 - 4C1 * a4 + 4C2 * a3 - 4C3 * a2 + a1 how ? , did i missed something id yes can you paste the link or explain ? Thanks Shashank On Wednesday, April 10, 2013 5:09:41 AM UTC+5:30, Shachindra A C wrote: Consider n = 5. Naming the array elements as

Re: [algogeeks] Re: Amazon interview question

2013-04-13 Thread pankaj joshi
in this Problem if the array is A[n] = {a0,a1,a(n-1),a(n)} after the second iteration, the value will be {a0 -2*a2+a3, a2 -2*a3 + a4, a3-2*a4+a5,, a(n-2)-2a(n-1)+a(n)} if we add all these terms then all the middle elements will be canceled out so the remaining will be. {a0-a2 -

Re: [algogeeks] Re: Amazon interview question

2013-04-13 Thread Shashwat Anand
On 4/13/13 10:05 PM, pankaj joshi wrote: in this Problem if the array is A[n] = {a0,a1,a(n-1),a(n)} after the second iteration, the value will be {a0 -2*a2+a3, a2 -2*a3 + a4, a3-2*a4+a5,, a(n-2)-2a(n-1)+a(n)} if we add all these terms then all the middle elements will be canceled

[algogeeks] Re: Amazon interview question

2013-04-09 Thread Don
It is O(N^2) because the inner loop takes N steps to execute and that loop will be executed N times. However, I would suggest not using recursion. There is no reason to not do it iteratively. Your recursive solution has no base case so it will recurse until your computer runs out of stack space,

Re: [algogeeks] Re: Amazon interview question

2013-04-09 Thread rahul sharma
i forgot to add base case..can add wen 2 elemnts are there then there sum is stored and we reurn from there...i m in hurry,,,sry for that,, On Wed, Apr 10, 2013 at 12:11 AM, Don dondod...@gmail.com wrote: It is O(N^2) because the inner loop takes N steps to execute and that loop will be

Re: [algogeeks] Re: Amazon interview question

2013-04-09 Thread rahul sharma
If you have any other solution ..please post that...i thnik recursion is ok with base case...we need to scan again after first iteration...?? On Wed, Apr 10, 2013 at 12:12 AM, rahul sharma rahul23111...@gmail.comwrote: i forgot to add base case..can add wen 2 elemnts are there then there sum

[algogeeks] Re: Amazon interview question

2013-04-09 Thread Don
int getsum(int *a, int n) { while(--n) { for(int i = 0; i n; ++i) a[i] = a[i+1] - a[i]; } return a[0]; } I'm not really clear about how it is intended to work. It seems that if you start with an array of N values, each iteration reduces the number of values by 1, so

Re: [algogeeks] Re: Amazon interview question

2013-04-09 Thread Shashwat Kumar
Recursion and iteration don't differ in this algorithm. But avoid using recursion if same can be done using iteration. In practical cases, system does not allow very large depth in recursion. So for large values of n, there can occur segmentation fault. On Tue, Apr 9, 2013 at 11:43 AM, rahul

Re: [algogeeks] Re: Amazon interview question

2013-04-09 Thread Shachindra A C
Consider n = 5. Naming the array elements as a1,a2,a3,a4,a5 , the final required sum would be 4C0 * a5 - 4C1 * a4 + 4C2 * a3 - 4C3 * a2 + a1. That is nothing but the pattern of a binomial expansion. Using this method, the complexity can be reduced to O(n). Correct me if I'm wrong! On Tue, Apr

Re: [algogeeks] Re: Amazon interview question

2013-04-09 Thread Shashwat Anand
On 4/10/13 12:13 AM, rahul sharma wrote: If you have any other solution ..please post that...i thnik recursion is ok with base case...we need to scan again after first iteration...?? First of all, the array size and number of iteration both won't be N or else the answer will always be 0. I take

Re: [algogeeks] Re: Amazon Interview Question

2013-04-03 Thread ashekhar007
hi sourab please explain what bit vector1 and bit vector 2 really are can you give an example please? On Saturday, February 16, 2013 11:20:59 PM UTC+5:30, sourabh wrote: you can solve this problem using bitvector/bitset. first scan : scan the array set the bit on odd occurrence and unset on

Re: [algogeeks] Re: Amazon Interview Question

2013-03-20 Thread sourabh jain
@sandeep he is talking about constant space. On Tue, Mar 19, 2013 at 5:31 PM, sandeep kumar sandeepkumar1...@gmail.comwrote: Hey what if while scanning through the array we create a BST n check simultaneously that : current node == current node's parent current node == current node's left

Re: [algogeeks] Re: Amazon Interview Question

2013-03-19 Thread sandeep kumar
Hey what if while scanning through the array we create a BST n check simultaneously that : current node == current node's parent current node == current node's left or right child -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

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

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] Re: Amazon Interview Questions

2013-03-12 Thread rohit jangid
these questions were asked for software dev. in amazon ? which round . looks like straight easy questions... On Sun, Mar 10, 2013 at 5:58 PM, Nishant Pandey nishant.bits.me...@gmail.com wrote: Ans to *Boundary traversal of a tree. Write the code. *1) you need to for preoder oder for left

[algogeeks] Re: Amazon Interview Questions

2013-02-17 Thread Tushar
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

Re: [algogeeks] Re: Amazon Interview Question

2013-02-16 Thread prakhar singh
Yes, thats a valid point Don. Thats what i meant when i wrote //is that correct? in the comments on the array line in code. int a[] = {2,2,3,3,3,1,1,4,4}; // is this correct? On Wed, Feb 13, 2013 at 9:09 PM, Don dondod...@gmail.com wrote: The xor approach only works if there are no values

Re: [algogeeks] Re: Amazon Interview Question

2013-02-16 Thread sourabh jain
you can solve this problem using bitvector/bitset. first scan : scan the array set the bit on odd occurrence and unset on even or 0 occurrence. second scan : shift all the odd occurring elements in beginning of array and even towards end. third scan : till end of odd occurring elements. take

Re: [algogeeks] Re: Amazon Interview Question

2013-02-13 Thread BUBUN SHEKHAR
Sachin Chitale, Dude the xoring operation will give us xor of numbers with freq 1 and 3 respectively. How do you filter out the number with the frequency 3?? On Tuesday, February 12, 2013 11:44:08 PM UTC+5:30, Sachin Chitale wrote: use ex-or operation for all array elements.. a^a=0 a^a^a=a

Re: [algogeeks] Re: Amazon Interview Question

2013-02-13 Thread sourabh jain
Search for BitSet/BitVector in java . On Tue, Feb 12, 2013 at 11:44 PM, Sachin Chitale sachinchital...@gmail.comwrote: use ex-or operation for all array elements.. a^a=0 a^a^a=a On Sun, Feb 10, 2013 at 8:22 AM, Mohanabalan D B mohanabala...@gmail.comwrote: can use counting sort On

Re: [algogeeks] Re: Amazon Interview Question

2013-02-13 Thread arun singh chauhan
@Sachin Chitale : Very good approach dude . thumbs up +1 -- Arun Singh Chauhan Engineer (RnD 2), Samsung Electronics Software Engineering Lab, Noida On Tuesday, February 12, 2013 11:44:08 PM UTC+5:30, Sachin Chitale wrote: use ex-or operation for all array elements.. a^a=0 a^a^a=a On

[algogeeks] Re: Amazon Interview Question

2013-02-13 Thread Don
The xor approach only works if there are no values which occur only once. But the problem statement indicates that some numbers occur once, some occur twice, and one occurs three times. So you will end up with prod equal to the xor of all of the values which occur once or three times. Put that in

Re: [algogeeks] Re: Amazon Interview Question

2013-02-12 Thread Mohanabalan D B
can use counting sort On Sun, Jul 15, 2012 at 6:37 PM, santosh thota santoshthot...@gmail.comwrote: If we can retrieve ith prime efficiently, we can do the following... 1.maintain a prod=1, start from 1st element, say a[0]=n find n th prime 2.check if (prod% (ith_prime * ith_prime )==0) then

Re: [algogeeks] Re: Amazon interview Question

2012-12-27 Thread Ritesh Mishra
@anurag : there is no need to SORT. as it will increase complexity O(n) to O(n log n). here is the correct code.. please look over it and notify me if i'm wrong . T.C. = O( n ) // ex: 1 4 3 2 0 i'm explaining on behalf of it. bool permute (int *arr , int N ) { if ( N=1 ) return false;

Re: [algogeeks] Re: Amazon interview Question

2012-12-27 Thread Hariraman R
Can anyone give me some idea if the given no is small like 12 then the next one is 17 On Mon, Dec 24, 2012 at 7:56 PM, marti amritsa...@gmail.com wrote: I REPEAT, THERE is no need to SORT; http://en.wikipedia.org/wiki/Permutation#Lexicographical%5Forder%5Fgeneration On Friday,

Re: [algogeeks] Re: Amazon interview Question

2012-12-27 Thread Anurag Gupta
Hi Ritesh Yeah, you are right. we do not need to sort. my bad Thank you for explaining clearly On Thu, Dec 27, 2012 at 4:29 AM, Ritesh Mishra rforr...@gmail.com wrote: @anurag : there is no need to SORT. as it will increase complexity O(n) to O(n log n). here is the correct code.. please

[algogeeks] Re: Amazon interview Question

2012-12-24 Thread marti
I REPEAT, THERE is no need to SORT; http://en.wikipedia.org/wiki/Permutation#Lexicographical%5Forder%5Fgeneration On Friday, December 14, 2012 11:56:16 AM UTC+5:30, tapan rathi wrote: For a given number, find the next greatest number which is just greater than previous one and made up of

Re: [algogeeks] Re: Amazon interview Question

2012-12-21 Thread Anurag Gupta
@marti your answer is completely wrong (check for 234987156221 ans is 2349871*61225 * whereas your answer would be 2349871*65225*) and we do need to sort On Mon, Dec 17, 2012 at 9:10 AM, marti amritsa...@gmail.com wrote: Yeah thanks Sandeep, theres an error in example...it should be

[algogeeks] Re: Amazon interview Question

2012-12-16 Thread marti
Here is what you do EG: 5436782 ans is 5436872 how did we arrive? FInd least index i, such that a[i-1] = a[i] starting from rigthmost 5436782 (8) Now , Find least index j such that a[j-1] = a[i-1]: 5436782 (7) swap them = 5436872 Now swap all values between i and j.

Re: [algogeeks] Re: Amazon interview Question

2012-12-16 Thread Shubham Sandeep
hello all... anwer to previous example would be 5436827 instead of 5436872please correct it :) On Sun, Dec 16, 2012 at 11:48 PM, marti amritsa...@gmail.com wrote: Here is what you do EG: 5436782 ans is 5436872 how did we arrive? FInd least index i, such that a[i-1] = a[i] starting from

Re: [algogeeks] Re: Amazon interview Question

2012-12-16 Thread ramchandra sankhala
Let the number is stored in an array a[n] with MSB at index 0... 1. i = n-1; reduce i till a[i]=a[i-1] i 0. If here i =0 means give number is largest possible number made out of digits otherwise i is pointing to a digit such that a[i]a[i+1] 2. find smallest digit from a[i+1 to n-1] just

[algogeeks] Re: Amazon interview Question

2012-12-16 Thread marti
Yeah thanks Sandeep, theres an error in example...it should be 5436827.However there is no need to sort. On Friday, December 14, 2012 11:56:16 AM UTC+5:30, tapan rathi wrote: For a given number, find the next greatest number which is just greater than previous one and made up of same digits.

[algogeeks] Re: Amazon Interview Question

2012-07-15 Thread santosh thota
For the series like 2,4,3,9,4,16,5,25 ur algo runs in o(n*n/2) =o(n^2) On Friday, 13 July 2012 13:16:50 UTC+5:30, jatin wrote: 1)Find product of the array and store it in say prod o(n) and o(1) 2)now traverse the array and check if static int i; tag: while(in) if( prod

[algogeeks] Re: Amazon Interview Question

2012-07-15 Thread santosh thota
If we can retrieve ith prime efficiently, we can do the following... 1.maintain a prod=1, start from 1st element, say a[0]=n find n th prime 2.check if (prod% (ith_prime * ith_prime )==0) then return i; else prod=prod*ith_prime; 3.repeat it till end On Thursday, 12 July 2012 10:55:02

Re: [algogeeks] Re: Amazon Interview Question

2012-07-14 Thread jatin
. Plus this will exceed O(n) in the worst case, as we may keep visiting the goto again and again. Not sure of its exact time complexity. -- From: vindhya chhabra Sent: 13-07-2012 17:46 To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Re: Amazon Interview

[algogeeks] Re: Amazon Interview Question

2012-07-13 Thread @jatin
Or we can make a BST from array list in o(n) then traverse it inorder-o(logn) but this solution requires o(logn) space though. On Friday, 13 July 2012 13:16:50 UTC+5:30, jatin sethi wrote: 1)Find product of the array and store it in say prod o(n) and o(1) 2)now traverse the

Re: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread adarsh kumar
@jatin: Your first method may be proved wrong. Here is a counter test case: Suppose the array is: 27 729 19683 2 3 3 27 3 81 729 Here, 81 occurs once, 19683 occurs once, 2 occurs once,729 occurs twice, 27 occurs twice, and 3 occurs thrice. You are supposed to return 3 But as per your method,

Re: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread vindhya chhabra
@adarsh But i think jatin has asked to check for the number( we achieved in step 1) occuring thrice or not..and in this check 27 will rule out.but i doubt the algo given by Jatin runs in O(n) time. please comment. On Fri, Jul 13, 2012 at 5:17 PM, adarsh kumar algog...@gmail.com wrote: @jatin:

RE: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread adarsh kumar
To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Re: Amazon Interview Question @adarsh But i think jatin has asked to check for the number( we achieved in step 1) occuring thrice or not..and in this check 27 will rule out.but i doubt the algo given by Jatin runs in O(n) time. please comment. On Fri

Re: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread jatin
@googlegroups.com Subject: Re: [algogeeks] Re: Amazon Interview Question @adarsh But i think jatin has asked to check for the number( we achieved in step 1) occuring thrice or not..and in this check 27 will rule out.but i doubt the algo given by Jatin runs in O(n) time. please comment. On Fri

Re: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread Dave
exact time complexity. -- From: vindhya chhabra Sent: 13-07-2012 17:46 To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Re: Amazon Interview Question @adarsh But i think jatin has asked to check for the number( we achieved in step 1) occuring thrice

Re: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread algo bard
chhabra Sent: 13-07-2012 17:46 To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Re: Amazon Interview Question @adarsh But i think jatin has asked to check for the number( we achieved in step 1) occuring thrice or not..and in this check 27 will rule out.but i doubt the algo given by Jatin

Re: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread Shruti Gupta
: 13-07-2012 17:46 To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Re: Amazon Interview Question @adarsh But i think jatin has asked to check for the number( we achieved in step 1) occuring thrice or not..and in this check 27 will rule out.but i doubt the algo given by Jatin runs in O

RE: [algogeeks] Re: Amazon Interview Question

2012-07-13 Thread adarsh kumar
+1. -- From: Shruti Gupta Sent: 14-07-2012 08:08 To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Re: Amazon Interview Question @jatin: even i think it will b more than O(n).. infact it will be O(n-square) in the worst case as if each hit is spurious(until

[algogeeks] Re: Amazon Interview Question

2012-07-12 Thread Dave
@Algo bard: No. You can do an O(n) time, O(n) space solution with a radix sort, or you can do an O(n log n) time, O(1) space solution with a variety of sorts. Dave On Thursday, July 12, 2012 12:25:02 AM UTC-5, algo bard wrote: Given an array of integers where some numbers repeat once, some

[algogeeks] Re: Amazon Interview Question

2012-07-12 Thread deepikaanand
If the assumption is that there is only one element which occurs once , some elements repeat twice and only one element which repeats thrice then following is the code according to the assumption made http://ideone.com/yseYy -- You received this message because you are subscribed to the

[algogeeks] Re: Amazon Interview Question

2012-06-16 Thread algogeek
could u explain how would you use a trie for this?? On Thursday, June 14, 2012 1:01:00 PM UTC+5:30, Mohit Rathi wrote: Hi, *There are two arrays of length 100 each. Each of these has initially n (n=100) elements. First array contains names and the second array contains numbers such that

[algogeeks] Re: Amazon Interview Question

2012-06-16 Thread enchantress
Store each of the words in array in a trie and mark the end of the word by its corresponding entry in the second array. Now if u are searching for a word it'll take O(length of word) if there is a mismatch at any point you know the word is not present in array1 and add it to the trie or else

[algogeeks] Re: Amazon Interview Question

2012-06-15 Thread enchantress
You can use a trie with end of word marked by its corresponding entry in array. On Thursday, 14 June 2012 13:01:00 UTC+5:30, Mohit Rathi wrote: Hi, *There are two arrays of length 100 each. Each of these has initially n (n=100) elements. First array contains names and the second array

Re: [algogeeks] Re: Amazon Interview Question

2012-06-15 Thread Amol Sharma
+1 for trie.. -- Amol Sharma Third Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99 http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/ On Fri, Jun 15, 2012 at 5:21 PM, enchantress

Re: [algogeeks] Re: amazon interview questions

2012-06-06 Thread Ashish Goel
Hassan geke should not be a valid string. The question states which have the same substring following it so here e follows e. There is no precondition that it has to follow immediate. Utsav: can you clarify? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081

Re: [algogeeks] Re: amazon interview questions

2012-06-06 Thread atul anand
nope geke is valid string.. here is the link from where question was taken http://geeksforgeeks.org/forum/topic/amazon-interview-question-password-checker On Wed, Jun 6, 2012 at 11:44 AM, Ashish Goel ashg...@gmail.com wrote: Hassan geke should not be a valid string. The question states which

Re: [algogeeks] Re: amazon interview questions

2012-06-06 Thread Hassan Monfared
geke is valid. BTW if you changeif(i=len) toif(i0) my code outputs geke is invalid.( what you desired) if geke is invalid regarding to the question, then you can achieve the answer in nLogn by sorting strings :s[0..n-1], s[1..n-1],s[n-1..n-1] and comparing adjacent members. Regards

Re: [algogeeks] Re: amazon interview questions

2012-06-06 Thread Darpan Baweja
@ashish:- geke is valid as repeated substrings should be immediate. On Wed, Jun 6, 2012 at 1:44 PM, Hassan Monfared hmonfa...@gmail.com wrote: geke is valid. BTW if you changeif(i=len) toif(i0) my code outputs geke is invalid.( what you desired) if geke is invalid regarding to the

Re: [algogeeks] Re: amazon interview questions

2012-06-06 Thread Ashish Goel
Thanks, my approach prepare a multimap of charcters and their positions by walking over the string. ashishis if is give string the multimap will have a-0 s-1,4,7 h-2,5 i-3,6 now for every character while walkingover the given string again, check from its multimap, if it is repeated, if not

Re: [algogeeks] Re: amazon interview questions

2012-06-05 Thread Ashish Goel
*tree substrings* tree--|---mississippim .. mississippi | |---i--|---ssi--|---ssippi i .. ississippi | | | | | |---ppi issip,issipp,issippi | | | |---ppi

Re: [algogeeks] Re: amazon interview questions

2012-06-05 Thread Ashish Goel
Hassan, can you explain your algo? Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Mon, Jun 4, 2012 at 11:20 AM, Hassan Monfared hmonfa...@gmail.comwrote: for -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] Re: amazon interview questions

2012-06-05 Thread Ashish Goel
The problem suggests that a character can't be more than once present and thereby it can be done by just having s bitmap and if a char repeats, any longer repeating substring will have those char repeated atleast twice, hence O(n) solution. Also, Hasaan: how is your algo O(n2) for for-while-for

Re: [algogeeks] Re: amazon interview questions

2012-06-05 Thread Hassan Monfared
Ashish: the algorithm passes over string and check if there is any substring with len=1 is repeated or not. if not, tries for substring with len 2,... and so on. max length of substring which can be repeated can be at most N/2. Regards, On Tue, Jun 5, 2012 at 10:48 AM, Ashish Goel

Re: [algogeeks] Re: amazon interview questions

2012-06-05 Thread Lomash Goyal
is geke is a invalid strng? On Tue, Jun 5, 2012 at 12:17 PM, Hassan Monfared hmonfa...@gmail.comwrote: Ashish: the algorithm passes over string and check if there is any substring with len=1 is repeated or not. if not, tries for substring with len 2,... and so on. max length of substring

Re: [algogeeks] Re: amazon interview questions

2012-06-05 Thread Hassan Monfared
yes It's valid, cuz it doesn't have any repeated substring next together On Tue, Jun 5, 2012 at 7:08 PM, Lomash Goyal lomesh.go...@gmail.com wrote: is geke is a invalid strng? On Tue, Jun 5, 2012 at 12:17 PM, Hassan Monfared hmonfa...@gmail.comwrote: Ashish: the algorithm passes over

Re: [algogeeks] Re: amazon interview questions

2012-06-04 Thread utsav sharma
@hasan :-ohhh sorry, i didn't see the outer loop yeah, it works but it is O(n^2), required solution is of O(n). On Mon, Jun 4, 2012 at 11:20 AM, Hassan Monfared hmonfa...@gmail.comwrote: utsav: It works fine, I did little bug fixing on boundaries as here goes : bool IsValid(string s) {

Re: [algogeeks] Re: amazon interview questions

2012-06-04 Thread Jeevitesh
i have not implemented it but i can you an idea how to approach it. Go to Each suffix in suffix or suffix array(I would prefer suffix array as it is easier) traverse the each suffix till you encounter the first letter of the suffix you are traversing and check to see this suppose i is the index

Re: [algogeeks] Re: amazon interview questions

2012-06-04 Thread Abhishek Sharma
I think it can be done by modifying the h-array and by making some changes in KMP-algorithm On Mon, Jun 4, 2012 at 9:35 AM, Jeevitesh jeeviteshshekha...@gmail.comwrote: i have not implemented it but i can you an idea how to approach it. Go to Each suffix in suffix or suffix array(I would

[algogeeks] Re: amazon interview questions

2012-06-03 Thread anugrah
So any string with two same characters is not valid?? for example : GEEK has E followed by E. So GEEK is also invalid? On Jun 3, 1:49 pm, Hassan Monfared hmonfa...@gmail.com wrote: bool IsValid(string s) {  for(int len=0;lens.len/2;len++)  {    int start1=0,start2=len+1;    

Re: [algogeeks] Re: amazon interview questions

2012-06-03 Thread Hassan Monfared
yes it's not valid On Sun, Jun 3, 2012 at 5:36 PM, anugrah anugrah.agra...@gmail.com wrote: So any string with two same characters is not valid?? for example : GEEK has E followed by E. So GEEK is also invalid? On Jun 3, 1:49 pm, Hassan Monfared hmonfa...@gmail.com wrote: bool

Re: [algogeeks] Re: amazon interview questions

2012-06-03 Thread utsav sharma
@hassan :- it will not work for many strings as you are checking from the mid of strings. try out ababcdef,aabc. @atul :- it should be done in O(n). On Sun, Jun 3, 2012 at 11:54 PM, Hassan Monfared hmonfa...@gmail.comwrote: yes it's not valid On Sun, Jun 3, 2012 at 5:36 PM, anugrah

Re: [algogeeks] Re: amazon interview questions

2012-06-03 Thread utsav sharma
@jeevitesh :- yes i am also thinking of suffix tree, but i am facing problem in implementing it. did you implement it ?? On Mon, Jun 4, 2012 at 9:11 AM, utsav sharma utsav.sharm...@gmail.comwrote: @hassan :- it will not work for many strings as you are checking from the mid of strings. try

Re: [algogeeks] Re: amazon interview questions

2012-06-03 Thread Hassan Monfared
utsav: It works fine, I did little bug fixing on boundaries as here goes : bool IsValid(string s) { for(int len=1;len=s.size()/2;len++) { int start1=0,start2=len; while(start2s.size()) { int i=0; for(;ilen start2+is.size() s[start1+i]==s[start2+i];i++); if(i=len)

[algogeeks] Re: Amazon Interview Question

2012-05-21 Thread Navin.nitjsr
I think adjacency list can be implemented by vector of vector. vector vectorint Nodes; The size of vector Nodes is total no of nodes. Every element of the vector will store all its adjacent edges. Nodes[i] is a vector containing all the edges adjacent to node i. So, we can copy the graph easily.

[algogeeks] Re: Amazon Interview Question

2011-09-24 Thread Asit Dhal
Here, can we use function for comparison ?? -- 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/-/ZgGYGAZwvcoJ. To post to this group, send email to

[algogeeks] Re: Amazon Interview question

2011-09-08 Thread Brijesh
Please reply with your alog...! -- 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/-/OGVCUV_hutUJ. To post to this group, send email to

[algogeeks] Re: Amazon - Interview Qn

2011-08-31 Thread Abhinav Vishwa
Recursion can be used as a approach. void disp( node * head, int i) { i++; if(i n || head == NULL) return; disp(head-next,i); if(head != NULL) cout head-data endl; } first call this function with pointer to head and 0; disp(first,0); then

Re: [algogeeks] Re: Amazon - Interview Qn

2011-08-31 Thread veera reddy
http://geeksforgeeks.org/archives/8014 On Wed, Aug 31, 2011 at 3:28 PM, Abhinav Vishwa avishw...@gmail.com wrote: Recursion can be used as a approach. void disp( node * head, int i) { i++; if(i n || head == NULL) return; disp(head-next,i); if(head != NULL)

[algogeeks] Re: Amazon Interview Q

2011-08-18 Thread Vijay Kansal
We should return curr-next in the last statement of ur code On Aug 18, 7:08 am, Dipankar Patro dip10c...@gmail.com wrote: A slight change in above code: make it while(cur cur-next) ^^ other wise the code will crash at last element in a prefect list, with no loop. On 18 August 2011 07:36,

Re: [algogeeks] Re: Amazon Interview Q

2011-08-18 Thread Dipankar Patro
we can do that too. But if I return cur then I can myself print cur, cur-next, cur-next-prev. for verification. On 18 August 2011 11:56, Vijay Kansal vijaykans...@gmail.com wrote: We should return curr-next in the last statement of ur code On Aug 18, 7:08 am, Dipankar Patro

[algogeeks] Re: Amazon Interview Q

2011-08-18 Thread WgpShashank
Hi Piyuesh Same Question i Faced Some Times Ago, Have a look at algo/code let me know if any test case missed ? http://shashank7s.blogspot.com/2011/05/wap-to-detect-loop-in-doubly-linked.html if we wants to remove loop from DLL, we can do in the same way we used to do for singly linked

Re: [algogeeks] Re: Amazon Interview Question

2011-06-29 Thread Wladimir Tavares
Hi Guys, The @pacific solution is the best? Wladimir Araujo Tavares *Federal University of Ceará * On Tue, Jun 28, 2011 at 7:26 AM, sunny agrawal sunny816.i...@gmail.comwrote: you can initialize it to (Max-Min+1) where Max = max of all elements Min = min of all elements Or simple

Re: [algogeeks] Re: Amazon Interview Question

2011-06-28 Thread vikas
what will be the oldDiff initially. can u plz explain with a egsample -- 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/-/NXQqyUTbdlkJ. To post to this group,

Re: [algogeeks] Re: Amazon Interview Question

2011-06-28 Thread sunny agrawal
you can initialize it to (Max-Min+1) where Max = max of all elements Min = min of all elements Or simple initialise it to a large integer like 0x7fff for 32 bit numbers. On Tue, Jun 28, 2011 at 3:32 PM, vikas mehta...@gmail.com wrote: what will be the oldDiff initially. can u plz explain

Re: [algogeeks] Re: Amazon Interview Question

2011-05-11 Thread anshu mishra
@pacific you are perfectly right but the order is not o(kn) its is O(k*n*log(n)) because to get the least number u have to use priority queue nd at every iteration (from 1 to k*n) u have to push and pop one single element. -- Anshuman Mishra IIIT Allahabad -

Re: [algogeeks] Re: Amazon Interview Question

2011-05-10 Thread pacific :-)
My approach : Have a pointer to the start (smallest of the array) of each of the N arrays. Until all pointers reach end of respective arrays : take the smallest value from all of the pointers and compute the difference between the smallest and the current pointers of each of the arrays

[algogeeks] Re: Amazon Interview Question

2011-05-09 Thread bittu
see here let me know if anything wrong..?? http://shashank7s.blogspot.com/2011/05/wap-to-find-minimum-difference-between.html Thanks Regrads Shashank the Best Way to Escape From The problem is to Solve it Computer Science Engg. BIT Mesra -- You received this message because you are

[algogeeks] Re: Amazon Interview question

2011-03-04 Thread Harshith
For an O(n) in place : http://arxiv.org/pdf/0805.1598 There are links to other algo's for the same problem with varying degrees of difficulty. I think it would be a very high expectation indeed, if they expected this solution from the interviewee. On Feb 28, 9:27 pm, Vinay Pandey

Re: [algogeeks] Re: Amazon Interview question

2011-03-01 Thread Vinay Pandey
I forgot to mention Time complexity: O(n), Space complexity: O(1) Assuming you accept my solution :-) On Mon, Feb 28, 2011 at 9:27 PM, Vinay Pandey babbupan...@gmail.com wrote: Hi, Here is my solution, let me know: /* a helper function */ void swap(int* arr, int index1, int index2) { /*

Re: [algogeeks] Re: Amazon Interview question

2011-03-01 Thread gaurav gupta
Here is one recursive solution I propose : consider example a1,a2,a3,a4,b1,b2,b3,b4 1. if n is even swap second Half of first array with first half of second array so it would be a1,a2,b1,b2,a3,a4,b3,b4 and it can be solved recursively so rearrange({a1,a2,a3,a4,b1,b2,b3,b4}) =

Re: [algogeeks] Re: Amazon Interview question

2011-03-01 Thread Vinay Pandey
Hi, Here is my solution, let me know: /* a helper function */ void swap(int* arr, int index1, int index2) { /* this is only to swap to integers */ arr[index1] = arr[index1]^arr[index2]; arr[index2] = arr[index1]^arr[index2]; arr[index1] = arr[index1]^arr[index2]; } /* Actual switching */ void

[algogeeks] Re: Amazon Interview question

2011-03-01 Thread Jammy
@gaurav. They way I see it it's O(nlogn)? you have n/4 for each level of the recursion tree and logn height. In total its O(nlogn) On Feb 28, 9:27 pm, Vinay Pandey babbupan...@gmail.com wrote: Hi, Here is my solution, let me know: /* a helper function */ void swap(int* arr, int index1,

[algogeeks] Re: Amazon Interview question

2011-02-28 Thread bittu
@jalaj U needs to clarify becoz what i can say that dat is overwritten in ur explanation so we loosing the original data where we are saving when we swapping the elements ur explanation seems to be right but little confusing @ujjwal i haven't tested ur code but i think its O(n^2) then why not

Re: [algogeeks] Re: Amazon Interview question

2011-02-28 Thread Arpit Sood
Are there any constraints in the problem, because it seems straight forward. if number of elements are 2n indexed from 0 to 2n-1 for i=0 to n-1: new_array[i*2]=old_array[i]; new_array[i*2+1]=old_array[i+n]; On Mon, Feb 28, 2011 at 7:41 PM, bittu shashank7andr...@gmail.com wrote: @jalaj

Re: [algogeeks] Re: Amazon Interview question

2011-02-28 Thread murthy.krishn...@gmail.com
how abt dis guys ?? #include stdio.h #include string.h #define MAX 100 int main() { int n; int i; int j; int it; char input[MAX]; char tmp; scanf(%s,input); n = strlen(input); i = j = n/2; for(it=1; itn-2; it++) { if(it%2 == 1) {

[algogeeks] Re: Amazon Interview question

2011-02-28 Thread bittu
@arpit otherwise it wont b amzon quest.. space dude..space is constants Thanks Shashank -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from

Re: [algogeeks] Re: Amazon Interview question

2011-02-28 Thread Arpit Sood
well space complexity should be mentioned in the question then, anyway, start with the second element put it at its correct location(say x), then take x put it at its correct location, this was when you do this n-1 time, you will get the correct answer because it forms a cycle. On Mon, Feb 28,

[algogeeks] Re: Amazon Interview question

2011-02-28 Thread Dave
@Arpit: The problem is that for certain values of n, you get more than one cycle, and the cycles are disjoint. You have to find all of the disjoint cycles and move the elements in each one. Dave On Feb 28, 12:25 pm, Arpit Sood soodfi...@gmail.com wrote: well space complexity should be mentioned

[algogeeks] Re: Amazon interview quesiton

2011-02-06 Thread algoseeker
I also encountered this question yesterday. This is my solution which i tested for a few sample cases. https://github.com/algoseeker/Interview/blob/master/Node.java I maintained a pointer to the Node where there should be creation of a new node. If the node created is left child, shift the

  1   2   >