Good Example of Implicit type using functions. Basically, it introduces the notion of boundedness in a polymorphic way.
- Feb 2017
-
dcsobral.blogspot.com dcsobral.blogspot.com
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
You need to note that, we start from 0,1 and 1,0 explicitly and not from 0,0 as that would lead to inplace turning.
-
-
-
stackoverflow.com stackoverflow.com
-
Our notes:
Iterator on keyset of Concurrent Hash Map does not use a separate snapshot copy of the map. So, you can witness some/none/all changes from other threads which are changing the same hashmap concurrently. It just reflects that this element existed in the hashmap at some point in time
In copy on write arraylist, the iterator will never pick up parallel changes by other threads, as it creates a snapshot copy at the time of iterator creation.
-
-
www.newthinktank.com www.newthinktank.com
-
Iterators to iterate over different classes, via a single interface.
-
-
stackoverflow.com stackoverflow.com
-
Integers are immutable, when you add two integers a new integer object is formed. Each integer internally keeps an int value which is final and can't be modified. + operator is compiler magic.
-
-
stackoverflow.com stackoverflow.com
-
Good example of how gof patterns are used in the JVM, Interger.valueOf keeps a configurable cache of Integer objects, note that integer objects are immutable.
-
-
docs.oracle.com docs.oracle.com
-
public static <T> List<T> asList(T... a)
Example of adaptor pattern. Here's the array serves as the backing point for the list, all methods of list api will be driven on basis of operations on the underlying array.
-
-
github.com github.com
-
Prototype design pattern with warlord, beast and mage, orcs and elfs, we keep a hashmap of each object ready in the factory at time of factory construction or lazily. Then when a new Warlord is requested, an existing warlord is cloned and used.
-
This example finally does a "new" inside clone(), rest is good.
-
-
stackoverflow.com stackoverflow.com
-
Diff between flyweight and object pool pattern lies in nature of vended object is immutable or mutable.
-
-
www.newthinktank.com www.newthinktank.com
-
Good example of composite design pattern.
-
-
sourcemaking.com sourcemaking.com
-
Here we can have two underlying data structure for a stack, an array or a list (similar to different platforms, example, unix, windows). An orthogonal set of hierarchy will be StackHanoi, which only allows to add an element if it is smaller than the top of the stack. Another hierarchy is FIFO implementation using stack. Now for each of the orthogonal implementation since we can choose a list or an array for the underlying implementation.
So, the underlying implementation forms another interface hierarchy of StackImpl, and actual Stack will "have a" StackImpl.
Now you may think it is similar to decorator-
differences: ->in decorator , you try to add behaviour on top of original functionalities. (like keeping a count whenver you call original functionalities like pop, push etc) but in bridge, you are selectively calling the original functionality or else you override the original. ->decorator here will only have one class that encapsulates all original impl but in bridge , your platform independent things are kept via 'has a' relation inside your handle, and your orthogonal functionalities will be extending that handle .
-
-
www.tutorialspoint.com www.tutorialspoint.com
-
Example of Adaptor pattern, slightly contrived.
-
-
www.tutorialspoint.com www.tutorialspoint.com
-
Nice example of Decorator pattern.
-
-
javarevisited.blogspot.com javarevisited.blogspot.com
-
Good explanation of Adaptor Design pattern
-
-
en.wikipedia.org en.wikipedia.org
-
The SOLID principle for OOPs.
-
-
www.javaworld.com www.javaworld.com
-
Good example of builder pattern.
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
Find the maximum path sum between "any" two leaves of a binary tree
-
-
www.informit.com www.informit.com
-
Good explanation of Clone, except doesn't cover the mandatory nature of Cloneable, one of the classes up our hierarchy should implement Cloneable, for you to call clone() on it, without encountering a runtime exception.
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
Start Node is not needed in this program ,see : http://code.geeksforgeeks.org/r7PSjB
-
- Jan 2017
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
int _bsearchForFO(int arr[], int left, int right, int elem) {<br> if(right - left <= 1) { if(arr[left] == elem) return left; else return right; } int mid = left+right/2; if(arr[mid] == elem) { return _bsearchForFO(arr,left,mid,elem); }else{ return _bsearchForFO(arr,mid,right,elem); }
}
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
The third tricky solution is same as Kadane, just that we can modify the original aray, we did Kadane with two variables, here we can use the diff array itself for storing the sums, so we check the sum of i-1 at i.
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
if an element is not at its correct position, that means repetition has already ocured in the left if the element is at its correct position, there is possibility of repetition in the right side
-
-
externaltable.blogspot.com externaltable.blogspot.com
-
Brendan Gregg's flame graphs are the starting ground for this work. Tanel Poder has also published several original investigations of stack profiling for Oracle troubleshooting, notably this included the blog post "Peeking into Linux kernel-land using /proc filesystem for quick’n’dirty troubleshooting". Kevin Closson has also published work on stack profiling with perf and OProfile and he is the author of SLOB, used in Example 2 of this post.
All things /proc !
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
just apply regular kadane from front and backward and do fw[i-1]+b[i+1] sum in the same way. Also have to keep max_so_far in consideration for an all positive number scenario. note- indexes are not visible from any of these approaches
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
xor was also used in the problem to find the no occrinf odd number of times in an array (all other numbers occur even number of times)
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
int i = minvalue; i <= maxvalue; i++
You have two options for the iteration in first loop:
Either sort the array and iterate over the elements present only in the array. Or iterate from min_value to max_value which checks every number, irrespective of its presence in given array or not.
-
You have two options for the iteration in first loop:
- Either sort the array and iterate over it.
- Or iterate from min_value to max_value
-
mark[j]
We can use the following condition as well:
value[j] == 0 || value[j/i] == 0
This is because in cases where value[j/i] =0 , the loop in doing redundant work.
-
value[j]
When none of the left or right subtree is taken,so 1 initially.
-
value[i] * value[j/i]
If you can arrange left subtree in x ways and right subtree in y ways, then you can have total x*y combinations for their parent, each of which will be a full binary tree..
-
!= j/i
This is to ensure cases where left and right subtree are same are not counted twice.
-
j/i <= i
This ensures that when we calculate value[j/i], it will be available.
-
- Full binary tree can have leaves at any level.
- Each node has either 2 or 0 children.
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
- if negative numbers are allowed, then the solution will fail because:
-1 -2 3 4 5
We would like to use -1,-2 for solution to 4.
Also ,if we have to find the maximum this logic will not work, because then again we will like to keep all numbers, and not just one of them which is solution assumes.
In general, if we have to minimize the result, then question will keep the restriction on skipping elements, but when we have to maximize the result, then question will put restriction on including the elements.
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
We want cases where maximum > k only.
9 8 7 1 2 3 4 19 12
No. of subarrays = subarrays of size 1 + subarrays of size 2 + subarrays of size 3 + .... subarrays of size n
= n + (n-1) + (n-2) + .... + 1 = n(n+1)/2
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
msum < arr[i]
Since we use less than here, so in cases of repetition of the minimum, we do have the first occurence only.
-
arr[R[i] + 1] -= 1;
This is because both the ends of the range li,ri are inclusive.
-
-
www.geeksforgeeks.org www.geeksforgeeks.org
-
recur[v] = false;
This is like making the node black, so basically
a b ccase 1: edges are a->b, a->c, c->b (not a cycle) case 2: edges are a->b, a->c, c->a (cycle)
When we are exploring c, b is black, considering we have already visited b first during dfs from a, and any link to black nodes do not constitute a cycle.
This is an overkill, as a node cannot have two neighbours in the given problem.
-