Re: [algogeeks] reverse a string efficiently

2012-11-27 Thread Pralay Biswas
Technically linear! On Mon, Nov 26, 2012 at 9:47 PM, shady sinv...@gmail.com wrote: what is the time complexity of this? str_reverse(str){ if(isempty(str)) return str; else if(length(str) = even) then split str into str_1 and str_2; (of equal length) (Calculate mid =O(1), then

Re: [algogeeks] reverse a string efficiently

2012-11-27 Thread Pralay Biswas
Yes, my bad. I din notice the recursion at all! Thot it to be a flat mid-split followed by a reverse followed by a concat. Thanks. On Mon, Nov 26, 2012 at 11:18 PM, atul anand atul.87fri...@gmail.comwrote: considering '+' , here will take Cn time . Here '+' is for concatenate , now this

[algogeeks] Re: reverse a string efficiently

2012-11-27 Thread Don
Reversing a string should be linear time. void reverse(char *str) { int i = 0; int j = strlen(str)-1; while(i j) swap(str[i++], str[--j]); } On Nov 27, 12:47 am, shady sinv...@gmail.com wrote: what is the time complexity of this? str_reverse(str){     if(isempty(str)) return

Re: [algogeeks] Re: reverse a string efficiently

2012-11-27 Thread Vineeth
i guess it should be swap(str[i++], str[j--]); because we already subtracted 1 On Tue, Nov 27, 2012 at 8:58 PM, Don dondod...@gmail.com wrote: swap(str[i++], str[--j]); --

[algogeeks] Re: Largest contigious subarray with average greather than k

2012-11-27 Thread Don
Define the deficit of a subarray S to be k*size(S)-sum(S), or how much its sum falls short of averaging k. If the deficit of the entire array is negative, the result is the entire array. Otherwise, the result is the subarray created by removing the smallest possible subarray from the front and

[algogeeks] Re: Largest contigious subarray with average greather than k

2012-11-27 Thread Don
Define the deficit of a subarray S to be k*size(S)-sum(S), or how much its sum falls short of averaging k. If the deficit of the entire array is negative, the result is the entire array. Otherwise, the result is the subarray created by removing the smallest possible subarray from the front and

[algogeeks] Re: Largest contigious subarray with average greather than k

2012-11-27 Thread Don
Define the deficit of a subarray S to be k*size(S)-sum(S), or how much its sum falls short of averaging k. If the deficit of the entire array is negative, the result is the entire array. Otherwise, the result is the subarray created by removing the smallest possible subarray from the front and

[algogeeks] Re: Openings in Amazon

2012-11-27 Thread Pankaj Kumar
Sir, I have sent you my CV on vivekr...@gmail.com. Hope you got that On Friday, November 23, 2012 9:29:29 PM UTC+5:30, Vivek Ramamurthy wrote: Hi, Amazon is hiring people for software development projects undergoing at Blore, Hyd and Chennai divisions.There are openings for Software