gstepanov@griddynamics.com
BAN USERcomapre interface,comparator class, equals and hashcode methods also used for this purpose. Finally you can use == operator to compare references by identity.
- gstepanov@griddynamics.com October 25, 2013By idea we can implemet this stack using tree. This tree has a root - beggining state. All leafs in tree connected in linked list. Each time we do push/pop - new branch is made and this new node added to linked list os states.
- gstepanov@griddynamics.com October 24, 2013Oh,it seems like NP-complete minimal vertex cover problem
- gstepanov@griddynamics.com October 24, 2013Can somebody explain semantics of fork? How does it fork current thread?
- gstepanov@griddynamics.com October 22, 2013very abstract question. Is it from interview or your job task?
- gstepanov@griddynamics.com October 22, 2013How we can move? Only down and right?
- gstepanov@griddynamics.com October 22, 2013maybe we can apply radix sort? Sort both list by second point, then by first and compare them.
- gstepanov@griddynamics.com October 22, 2013I agree, modern compiler should convert String to StringBuilder. String literals are pooled in String pool.
- gstepanov@griddynamics.com October 11, 2013This problems seems more complex .
General idea is to build Trie over all these strings, that perfrom traverse over tree, after that select leaf node that has maximum amount of nodes as it's ancestors.
Code from "Java concurrency in Practice"
public class Memoizer<A, V> implements Computable<A, V> {
private final ConcurrentMap<A, Future<V>> cache
= new ConcurrentHashMap<A, Future<V>>();
private final Computable<A, V> c;
public Memoizer(Computable<A, V> c) { this.c = c; }
public V compute(final A arg) throws InterruptedException {
while (true) {
Future<V> f = cache.get(arg);
if (f == null) {
Callable<V> eval = new Callable<V>() {
public V call() throws InterruptedException {
return c.compute(arg);
}
};
FutureTask<V> ft = new FutureTask<V>(eval);
f = cache.putIfAbsent(arg, ft);
if (f == null) { f = ft; ft.run(); }
}
try {
return f.get();
} catch (CancellationException e) {
cache.remove(arg, f);
} catch (ExecutionException e) {
throw launderThrowable(e.getCause());
}
}
} }
this is valid only if input is like this, but your solution doesn't work properly for general case.
- gstepanov@griddynamics.com October 10, 2013Any decreasing or increasing sequence of elements will degenerate BST to linked list.
- gstepanov@griddynamics.com October 08, 2013It depends on what isolation level you want to support. You can use locks per table, rows ..
- gstepanov@griddynamics.com October 07, 2013The order of elements to be print is not determined, because we write them to different streams. Each will be flushed in it's own time. So we will get different results.
- gstepanov@griddynamics.com October 07, 2013I think it's to much for this task, maybe there is any better solution
- gstepanov@griddynamics.com October 04, 2013Let assume we have n digits. Each of them will appears on i-th position n!/n times. So the general formula is :
n!/n = 6
(1 + 2 + 3 + 4) * 6 * 4 = 240
you have O(n^2) complexity, i think they wanted O(n) solution of this problem...
- gstepanov@griddynamics.com October 02, 2013Perform simple graph traversal either DFS or BFS(you can do it even in parallel)
- gstepanov@griddynamics.com September 29, 2013Maybe you should use hashing and Rabin-Karp Algo?
- gstepanov@griddynamics.com September 29, 2013i think the Fenwick tree for sum on array could be more appropriate. It compute sum from range [L,R] bt O(lgN) and change operation for O(lgN)
- gstepanov@griddynamics.com September 18, 2013As i think hash it is attempt to map objects from some range and which has many parametres, maybe even infinite to finite range of values.
HashMap uses linkedlist to store enries for the sake of fast insertion to tail.
Are java locks such as ReadLock and WriteLock Are allowed? If yes os it's quite simple task.
- gstepanov@griddynamics.com September 16, 2013Maybe you should use sun.misc.Unsafe class?
- gstepanov@griddynamics.com September 12, 2013How about next idea.
The last element of second array - let call it array of inversions in following, is always that we have in desc order. For example.
3 2 1. 2
0 1 1 - is element with index 1 in desc order. so it must be placed the in that way:
* * 2
0 1 *
so 1 - is element with 1 index in desc order without 2. it must be placed there
* 1 2
and following
3 1 2
We process array from right to left. element i must be placed with element from first array without already processed element in desc order.
comapre interface,comparator class, equals and hashcode methods also used for this purpose. Finally you can use == operator to compare references by identity.
- gstepanov@griddynamics.com October 25, 2013