glebstepanov1992
BAN USER- 9of 9 votes
AnswersArrayList list = new ArrayList();
- glebstepanov1992 in Russia for Yandex
what would you improve in this code?| Report Duplicate | Flag | PURGE
Developer Program Engineer - 0of 0 votes
AnswersHow to effectively implement and index for facet filtering?
- glebstepanov1992 in United States| Report Duplicate | Flag | PURGE
please,clafiry the question
- glebstepanov1992 December 23, 2013Best log(N)
Worts O(Fib(N))
Actually this problem can be converted from Hamilton to Eulerian proble,
Let bit strings length k-1 be your vertexes and bit strings with length k your edges.
vertex is source of edge if vertex bit string is a prefix of the edge and vertex is a source if edge is a suffix of the edge string.
vertex 0111
edge 10111
edge 01110
As you see one edge can be glued with another if they have same vertex
->0->
So in this problem all you have to do it's just to travel all edges only once - it is Eulerian cycle.
public static boolean exists(int number,int k) {
for(int i = 2;i <= k && i <= number;i++) {
if(number % i == 0) {
return false;
} else {
number -= (number / i);
}
}
return true;
}
3
/ \
2 6
/ \
1 7
What if target is 1 ?
please, can you give some example of time series?
- glebstepanov1992 December 17, 2013Why you consider 0 as a step?
- glebstepanov1992 December 17, 2013What the degree of separation means? it is a distance on the graph?
- glebstepanov1992 December 17, 2013Look at my comment above
- glebstepanov1992 December 13, 2013Look, you-ve got some input value K, in this example it would be K=5.
You need to generate minimal lenght sequence S from 0 and 1 ,each cyclic substring of which will be different bit sequence with lenght 5.
Simple example K = 3.
00011101
we have from left to right
000
001
011
111
110
101
010
Read about De Brujin sequences and graphs, i think it will clarify the problem for you.
Your sample data seems incorrect, why you need two operations in fourth line, if you can make this expression valid RPN by only one replace operation:
*xx -> xx*
Count of 0 an 1 will grow proprtionally to Fibonachi sequence :
fib(3) 3
fib(4) 5
fib(5) 8
fib(6) 13 ans so on...
Can you explain what is the problem is? You need to traverse folder's tree? User BFS and with FIFO queue or DFS with Stack all of them will be stored in Heap and won't cause StackOverflowError , just OutOfmemoryError)))
- glebstepanov1992 December 12, 2013I think problem is defined a little bit wrong. First of all if we talk about permutations - the order matters, so in your problem we are talking about subsets. For example if we have one array and we need to form all subsets of it array. You can whether take an element from array or not. if lenght of array if n, then you've got 2^n subsets and you can represent it like bit strings.
000
001
010
011
100
101
110
111
You can form form subsets of each array and answer will be Cartesian product of theese sets.
Ok,so you've got a lot of patterns that you know in advance and you receive strings, you need to answer whether that string are represented in dictionary or not. I think you should preproceed dict, build something like trie (Aho-Corasik algo). Second, to be sure that all words from string are in dict Aho Corasik will be preferable. Also i suggest you to read about suffix trie and Ukkonen algo.
- glebstepanov1992 December 11, 2013Please can you clarify the quiestion? You've got array of strings, how would you search string in dictionary?
Check whether string contains only words from dict or not?
I think you should build trie from these strings, so when you go from root to nodes, all strings that would be under current node - will be answers. For better performance you can store all references on all strings each node belongs to. so complexity wiil be O(n), where n - is lenght of input.
- glebstepanov1992 December 10, 2013Let consider the graph, whose vertexes are 5-bit sequences. two vertexes are adjecent when one is prefix or suffix of another. Everything we need - it is to build that graph with 32 vertexes And find out Eulerian cycle on it. it will be the number.
- glebstepanov1992 December 09, 2013Let consider the graph, whose vertexes are 5-bit sequences. two vertexes are adjecent when one is prefix or suffix of another. Everything we need - it is to build that graph with 32 vertexes And find out Eulerian cycle on it. it will be the number.
- glebstepanov1992 December 09, 2013maybe we should use rotation mechanism to do this?
- glebstepanov1992 December 09, 2013maybe we have to find something like De Bruijn sequence?
- glebstepanov1992 December 09, 2013We have to put begin and end points to an array with flag equals to 1 when it is begin an -1 when it's end. After that sort points by time. Then we scan an array.
int balance = 0;
int max = 0;
int maxBegin = 0;
int maxEnd;
for(int i =0;i < array.lenght;i++) {
balance = 0;
int j = i;
do{
balance += array[j];
}
while(balance > 0);
if(j - i > max) {
max= j - i;
maxBegin = i;
maxEnd = j;
}
i = j;
}
Look in HashMap sources from jdk))) Actually,what kind of hashtable they wanted? Open or close adressing?
- glebstepanov1992 November 16, 2013Maybe you should implement linked list based on something like that:
class Node {
Node prev;
Node next;
Object value;
Look in ArrayList sources from jdk =)
- glebstepanov1992 November 15, 2013What the problem? Implement Map<?,?> interface
- glebstepanov1992 November 15, 2013MinHeap ,if it is full exract min and put latest log message there. Or maybe we can adjust Splay tree to this purpose.
- glebstepanov1992 October 06, 2013Object is allocated in Heap, but reference push to the stack. Also you should know that each thread has his own stack.
- glebstepanov1992 October 06, 2013Serialization are simple but it has lack of performance. It supports UID so we can compare versions f serialized object. Externalizable is better when you wan to get better performance and use less memory. Also it Externalizable can be useful when you want to catch moment of serialization and initialize some transient fields in your own way.
- glebstepanov1992 October 06, 2013HashMap. Each range should have unique hash. Very simple question.
- glebstepanov1992 October 06, 2013We can fix it by adding some kind of compaction. When average size of free block reaches some threshold - invoke compaction.
- glebstepanov1992 October 04, 2013First of all you've got a mistake in result.
(2,6,4)/3 = 4. But you wrote 3.
it's not an optimal solution by space complexity, but works in O(N).
int []a = new int[]{2,6,4,2,3};
int N = 3;
int[] sum = new int[a.length];
int[] avg = new int[a.length];
for(int i = 0;i < a.length;i++) {
if(i > 0)
sum[i] += sum[i - 1];
sum[i] += a[i];
if(i >= N) {
avg[i] = (sum[i] - sum[i - N])/ N;
} else {
avg[i] = sum[i] / (i + 1);
}
System.out.println(avg[i]);
}
}
In java we can divide array between N threads to accumulate numbers, also we should use CyclicBarrier for gathering results of all threads.
- glebstepanov1992 October 04, 2013What is the complexity of your solution?
- glebstepanov1992 October 03, 2013What if possible range is from 0 to 987654321 it makes this problem more complex
- glebstepanov1992 October 03, 2013One more idea to build suffix trie on this array. We have to concat all strings like s1$1s2$2..sn$n and insert specific delimeters, that will be unique in all string. Than we find lowest vertex, that contains under itself all strings. It's also popular problem how to find leats string, that contains another.
- glebstepanov1992 September 22, 2013I think we can youse graph algrithm approach to this problem. It's quite common in genome assbmling problem to build de Bruijn graph and find out Euler cycle on it. So let'sbuild graph, where strings are vertexes, and edge from u to v means that string corresponds to u contain suffix that also is preffix of string v. So the solution of this problem is to find Euler cycle on this graph.
- glebstepanov1992 September 22, 2013I think either sample data or question is not clear.
- glebstepanov1992 August 11, 2013we can use replication. send chunk on 3 machines, for example
- glebstepanov1992 August 09, 2013I see, but can you explain what the difference between using array,as you did and hashmap. Hash map has its own array and Character uses Objects native hashcode, that is almost unique per each object.so yo'll have nice disribution. You can also adjust size of hashmap from the begging.
- glebstepanov1992 August 09, 2013thats nice, but your idea is based on ASCII alphabet. How about if you using UTF16. a lot of languages and characters, So it means that your memory grows O(n), not the O(1).
- glebstepanov1992 August 09, 2013acunt -good naming))
- glebstepanov1992 August 09, 2013Map-Reduce?)))
- glebstepanov1992 August 09, 2013Yep,you are right. Your idea about counting is good))
- glebstepanov1992 August 08, 2013How about that idea. If you encounter element on position i and it is not equal to i. Than you have to place value a[i] to position with index a[i] e.g a[a[i]] = a[i]. But if this position is already captured with right element you go forward. It is preproccessing made by O(n). The next cycle you just scan array, and if value of element with index i isn't equal to i it means that we haven't element with value i. Here is code of my solution.
public static void checkMissedElements(int[] array){
for (int i = 0;i < array.length;i++){
while(array[i] != i && array[array[i]] != array[i]){
int buf = array[i];
array[i] = array[array[i]];
array[buf] = buf;
}
}
for (int i = 0;i < array.length;i++){
if (array[i] != i){
System.out.println("Element " + i + " is missed");
}
}
}
So a ^ b ^ a ^ b == 0 in your example. It will be always true because the order of xor doesn't matter.
- glebstepanov1992 August 07, 2013Oh,thanks. I've found a mistake in my solution.
Actually i meant that
char sum = 0;
for(int i = 0;i< strlen(s1);i++){
sum ^= s1[i];
sum ^= s2[i];
}
So each element of s1 which present in s2 will exclude both from sum by xor. It was my idea.
- glebstepanov1992 August 07, 2013what about the next algo
char sum = 0;
for(int i = 0;i < strlen(s1);i++) {
sum += (s1[i] ^ s2[i]);
}
if(sum == 0 )
return true;
else
return false;
So if s1 is just only permutation of s2 characters it meants that each symbol c1 in s1 has equal in s2. So c1 xor c2 == 0.
- glebstepanov1992 August 07, 2013Can you tell is this tree a BST?
- glebstepanov1992 August 07, 2013
RepConnieLavender, Animator at Altera
My name is ConnieLavender . I am working as a Broker associate . I love field work and visiting different places to ...
RepEllenaSimon, Animator at ABC TECH SUPPORT
Hello I am an event planner and I have been working in this field for almost 5 years. For a ...
Repjennykyiler, Area Sales Manager at AMD
Jenny , an Assistant Secretary with a track record of employer satisfaction in performing various administrative tasks, and completing visual presentations ...
Repamberdjohnson859, Backend Developer at ABC TECH SUPPORT
We are Responsible Environmental Technicians utilizing all of the resources available to develop practical solutions to corporate issues. Currently doing ...
RepAarnaCleark, AT&T Customer service email at ABC TECH SUPPORT
I am a detail-oriented technical manager with exceptional leadership skills and talent for creative marketing. I am an expert producer ...
RepJesseCarlson, Cloud Support Associate at Alfa Chemaical Laboratory
Jesse , a video producer with 4 years of experience in running production processes from start to finish. Excellent at client ...
Repchrishwalsh369@gmail.com, Android Engineer at ABC TECH SUPPORT
A computer operator is a role in IT that oversees the running of a computer system.Apart from this, today ...
RepSophiaLopez, Analyst at AMD
I am a skilled freelance graphic designer with over a decade of experience in the field. I am dedicated to ...
RepEllaFlores, Associate at Alcatel Lucent
Ella , a Tour bus driver in Sounds Great company Inc. A charter bus driver is responsible for providing comfortable and ...
Repsarahchannah745, Android Engineer at ASAPInfosystemsPvtLtd
Hello, I am an information records clerk.We are responsible for maintaining their company records in a complete and orderly ...
RepManilaRoche, Animator at Abs india pvt. ltd.
Manila , an extensive executive assistant with experience of 4 years in the field of administrative functions, managing the office of ...
Replimachiya788, Associate at ABC TECH SUPPORT
LeviWebber , is a Housekeeping cleaner at Exact Solutions . I am also exploring new things . Mayong Assam tantrik contact number . Housekeepers ...
Repjohnsantana9ytt9, Backend Developer at Accolite software
I am working as a Support service manager at Pro Star Garden Management . I had a different experience while working ...
RepAahnaAllen, AT&T Customer service email at A9
I am a multilingual Judge with 5 years of combined experience in presiding over court proceedings, prosecuting cases, and tirelessly ...
Rephuslafenena, Backend Developer at Absolute Softech Ltd
I am working as a Teletype operator at Midwest TV & Appliance . It's been almost ten years since I've ...
Repathenajbarnarda, Android Engineer at ABC TECH SUPPORT
I am a graduate in Civil Engineering with nearly 7 years of experience in planning and implementing technical solutions for ...
RepEllaScotz, abc at A9
I am a creative designer with innovative ideas and a unique approach to visuals. I am also a skilled painter ...
RepMarshaSimon, Game Programmer at ASU
I am Hayley , a freelance artist with 7 years of experience in creating impressionist works. My most recent work was ...
RepJenniaLopez, Associate at Absolute Softech Ltd
Jennia , a hard-working Packer with a strong determination to finish all assignments in a timely manner. Replaces , operates and maintains ...
RepEvaSanchez, Animator at Abs india pvt. ltd.
Eva , Manufacturing Worker with 3+ years of experience working in Dynatronics . Went for traveling around the world and gets to ...
RepEzraDavis, abc at A9
I am a hardworking and disciplined newly-certified architect with internship experience in designing commercial buildings and creating accurate 2D and ...
Replesamean618, Android Engineer at Adap.tv
Working as a Choreographer it's almost 10 years at Happy Bear Investment . Here I am dealing with different people ...
Reppamelajones9873, Area Sales Manager at Facebook
Hello I am Pamela Jones. I am an Animal Control Worker Here, Animal control officers are generally employed by a ...
RepAnaCardenas, Android Engineer at Allegient
Working as a Window clerk at EnviroSource Design for almost 10 years . Here I help people to guide . End a ...
RepGarzaHodge, Backend Developer at Apache Design
I am Garza, and I work in many different research, education, and health care settings with varying roles, levels of ...
Repggroverwmiller, Android Engineer at 247quickbookshelp
Hello I am a Budget officer with 5 years of experience. The Budget Officer implements budgeting and financial record keeping ...
Repericsumm059, Backend Developer at ASU
My name is EricSummey . I am working as a Sound engineering technician at Foreman & Clark . as a sound technician it ...
RepBertMusi, Consultant at Accenture
I am a service technician working at Parade of Shoes . It's been almost 5 years since I have been ...
RepSusanBrown, Accountant at AMD
I am a resourceful and seasoned Screen Printing Machine Operator with a strong customer service record across a range of ...
Repchomeshgeles, Android Engineer at ABC TECH SUPPORT
ReevesMildr , a builder working at Independent Investors . It has been almost 5 years since I have been working here. I ...
RepArnoldTate, Title searcher at Keeney's
I am a Title searcher with 8+ years of experience . In real estate business and law, a title search or ...
RepJeremyBrett, Consultant at Capgemini
Jeremy , a Business Administrator with more than 4 years experience helping companies from various industries plan, organize and control specific ...
Reverse Poland Notation
- glebstepanov1992 December 23, 2013