Bruce
BAN USERjust one more way to do it.
print all the subsets one by one and while printing each subset, keep adding them in reversed format in a prefix tree. each time you add a subset, check if its already present.
if it is discard it otherwise, add print and add it to prefix tree in reversed format.
just a question, when you change a cell to 0 (let's say during diagonal process), you would still want to check for longest queue of 1s in that row. but if you had changed that cell to 0 in diagonal run, that won't give you correct solution for row or column when their turn come to check, would it?
- Bruce October 13, 2012Since this answer will depend on language, here is my answer based on C++
I don't believe that there is anything like "template class" in c++. C++ only allow you to define templates and these templates are what which define the classes which people usually think that it means "class template".
Let me try to explain with example.
template <class typeName> class myExampleClass{
...
};
Now what we have here above here is a class template. Now when you declare something like
myExampleClass<int>
is class myExampleClass which is created, works on it and the behavior is defined by class template given above. "template class" doesn't make any sense as far as C++ is concerned.
- Bruce October 13, 2012
for an array maintain a sum array where sum[i] will be sum of all elements from 0 to i-1
- Bruce October 27, 2012Once you do that, find out the 2 elements in this array whose difference is max.
for example
array 1 2-1 -9 11 23 0
sum 0 1 3 2 -7 4 27 27
here it will be 27 and -7 so answer would be subarray from index 4 to 6. There could be bugs regarding choosing right index but i hope you got the idea.