[algogeeks] print spiral

2012-06-15 Thread Ashish Goel
given a matrix m*n print elements in spiral eg 1 2 3 4 5 6 = 1,2,4,6,5,3 1 2 3 =1,2,3 i wrote following code but for the case 2 printing 1,2,3,2 I wish to avoid keeping a counter of how many elements have been print so far... void spiral(int a[], int m, int n) { while ( (rs(m+1)/2)

[algogeeks] water trap

2012-06-15 Thread Ashish Goel
question @ http://www.leetcode.com/groups/twitter-interview/forum/topic/rain-water-trap-2d-version/ can someone help please Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 -- You received this message because you are subscribed to the Google Groups

Re: [algogeeks] print spiral

2012-06-15 Thread Guneesh Paul Singh
void spiral(int a[][],int m,int n) { int c=1; -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Microsoft Interview Question

2012-06-15 Thread Guneesh Paul Singh
void change(int a[],int n) { int i,j; i=0; j=1; while(injn) { if(ji) j=i+1; else if(a[j]0a[i]0) { swap(a,j,i); } else { if(a[j]0) j++; else i++; }

Re: [algogeeks] Microsoft Interview Question

2012-06-15 Thread Shubham Sandeep
@guneesh your code fails to keep order b/w 3 and 4 in the above example On Fri, Jun 15, 2012 at 2:40 PM, Guneesh Paul Singh gunees...@gmail.comwrote: void change(int a[],int n) { int i,j; i=0; j=1; while(injn) { if(ji) j=i+1; else

Re: [algogeeks] print spiral

2012-06-15 Thread utsav sharma
check no. of elements printed in all inner for loop also for (int j=c;jn-c-1 cntm*n;j++) {printf(%d ,a[r][j]); cnt++;} for (int i=r;im-r-1 cntm*n;i++) {printf(%d ,a[i][n-c-1]); cnt++} for (int j=n-c-1 cntm*n;jc;j--) {printf(%d ,a[m-r-1][j]); cnt++} for (int i=m-r-1

Re: [algogeeks] water trap

2012-06-15 Thread utsav sharma
pls explain the output On Fri, Jun 15, 2012 at 1:13 PM, Ashish Goel ashg...@gmail.com wrote: question @ http://www.leetcode.com/groups/twitter-interview/forum/topic/rain-water-trap-2d-version/ can someone help please Best Regards Ashish Goel Think positive and find fuel in failure

Re: [algogeeks] 4Sum

2012-06-15 Thread Shashank Narayan
Its simple varition of 3 sum problem , using hask table u can easily do it . let s=a+b+c+d can be written as b+c+d=s-a; - 3 SUM Try it let me know i find any difficulty :) On Fri, Jun 15, 2012 at 3:50 PM, Akshat Sapra sapraaks...@gmail.com wrote: Given an array *S* of *n*

[algogeeks] Re: Basics of Cloud Computing

2012-06-15 Thread shiv narayan
could you please provide free E-copy ? On Saturday, 9 June 2012 22:00:52 UTC+5:30, Ravi wrote: Hi All, Hope you are all doing great. I am a cloud engineer and specialize in cloud computing development and architecting as well big data analysis. Check out my blog for my views @

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

2012-06-15 Thread shiv narayan
although we know this is compiler dependent , but still such questions are very frequent in some local competitions and can be found in some old books too. is it possible to have such questions in any company placement paper or interview ? On Thursday, 14 June 2012 11:41:04 UTC+5:30, Ajesh js

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

2012-06-15 Thread Karthikeyan V.B
Complexity : O(n^3) import java.util.*; public class Solution { public ArrayListArrayListInteger fourSum(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function ArrayListArrayListInteger arr=new ArrayListArrayListInteger(); Arrays.sort(num); int

[algogeeks] Re: No of tri-angles

2012-06-15 Thread shiv narayan
this is the running code to find no of triangles using brute force technique logic: in a triangle having sides a,b,c; then a+bc(if c is greatest side) correct me if i am wrong. #includeiostream #includeconio.h using namespace std; int max(int a,int b,int c) { return ((ab?a:b)c?(ab?a:b):c); }

Re: [algogeeks] print spiral

2012-06-15 Thread Ashish Goel
yes, using count i solved this, but IMHO, this should be done without this count somehow.. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Fri, Jun 15, 2012 at 3:14 PM, utsav sharma utsav.sharm...@gmail.comwrote: check no. of elements printed in

Re: [algogeeks] Re: No of tri-angles

2012-06-15 Thread Amol Sharma
sry ignore the last comment for i wanted to say - your algo will work only when the numbers given are consecutive. -- Amol Sharma Final Year Student Computer Science and Engineering MNNIT Allahabad http://gplus.to/amolsharma99

Re: [algogeeks] 4Sum

2012-06-15 Thread Amol Sharma
O(n^3) is straight forward: find all triplets and store them in an array say sum. and then for each triplet do binary search for (target-sum[i]) in the given array. is solution better than O(n^3) possible ? -- Amol Sharma Final Year Student Computer Science and Engineering MNNIT Allahabad

Re: [algogeeks] water trap

2012-06-15 Thread Hassan Monfared
Hi, I solved it with a recursive solution and published in my blog : http://codingways.blogspot.com/2012/06/rain-water-trap-problem-2d-version.html please let me know if you have any idea. Regards, Hassan On Fri, Jun 15, 2012 at 2:15 PM, utsav sharma utsav.sharm...@gmail.comwrote: pls explain

Re: [algogeeks] 4Sum

2012-06-15 Thread Hemesh Singh
Find all b[k]=a[i]+a[j] for the given array a. Iterate over all elements of this array b. Let the sum be (a+b). Now binary search (target - (a+b) ) in the array b. Complexity : O( (N^2)( log (N^2) ) ) Correct me if i am wrong. On Fri, Jun 15, 2012 at 8:41 PM, Amol Sharma amolsharm...@gmail.com

Re: [algogeeks] Re: Book Feedback needed for book from Narasimha Karumanchi

2012-06-15 Thread Hemesh Singh
@Saurabh : That's http://www.squifer.com/ http://www.squifer.com/document/e6e6192d75/Data-Structures-And-Algorithms-Made-Easy-%28for-Interviews%29-Programming-Interview-Questions/ Some chapters of the book are available here. On Thu, Jun 14, 2012 at 11:46 PM, saurabh singh saurab...@gmail.com

Re: [algogeeks] Directi Question

2012-06-15 Thread Hemesh Singh
At first look it appears to be a simple problem of discrete binary search. Take sum of b[i] as the upper_bound and 0 as the lower bound. Then apply a simple binary search for the number of pages that can be given to a student. Complexity : O(N log( sum( B ) ) ) On Thu, Jun 14, 2012 at 12:26 PM,

Re: [algogeeks] 4Sum

2012-06-15 Thread sanjay pandey
@hemesh cud u plz elaborate wat is b[k]=a[i]+a[j]...n also ur solution... -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Directi Question

2012-06-15 Thread Shubham Sandeep
wat constraints does dis bring in the question... Also the books are arranged in a certain order and this order must never be changed. does this imply --- a student gets only consecutivly numbered book if not then sort the array B in decreasing order in Onlogn take another array S of k

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

2012-06-15 Thread Hemesh Singh
+ 1 for DK's solution. Is that a standard algorithm coz I feel like I have heard it somewhere ?? On Mon, Aug 8, 2011 at 1:37 AM, DK divyekap...@gmail.com wrote: @KK: DFS and BFS are O(N) and Floyd Warshall is O(N^3). Could you please state how you can use the traversals directly to get the

Re: [algogeeks] Re: Book Feedback needed for book from Narasimha Karumanchi

2012-06-15 Thread Ashish Goel
bought this book and i am quite impressed with the quantity and quality of code. Recommend this with programming pearls, prog interview exposed, cracking the coding interview. Best Regards Ashish Goel Think positive and find fuel in failure +919985813081 +919966006652 On Sat, Jun 16, 2012 at

[algogeeks] Re: Directi Question

2012-06-15 Thread shiv narayan
On Jun 16, 2:1@shubham couldnt understand following logic in you algo please explain when first k elemnts traversed then traverse again k elemnts of B and S[2*k-i]+=B[i])...again S[i-2*k]+=B[i][.so on till B is traversed completely. 6 am, Shubham Sandeep s.shubhamsand...@gmail.com wrote: wat

[algogeeks] Re: No of tri-angles

2012-06-15 Thread shiv narayan
@anmol my algo will work even if nos are not in ascending order .correct me if i am wrong. On Jun 15, 7:45 am, Amol Sharma amolsharm...@gmail.com wrote: sry ignore the last comment for i wanted to say - your algo will work only when the numbers given are consecutive. -- Amol Sharma Final

[algogeeks] Re: No of tri-angles

2012-06-15 Thread enchantress
@amol True, but the question suggests they are . If they arent then it'll require sorting the array and then binary search for largest index for which a[index] a[i]+a[j] .. Then required triangles are index-j for looped values i and j. On Friday, 15 June 2012 20:15:26 UTC+5:30, Amol Sharma