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)
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
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
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++;
}
@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
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
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
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*
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 @
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
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
+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
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
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);
}
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
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
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
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
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
@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
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,
@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
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
+ 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
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
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
@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
@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
28 matches
Mail list logo