glebstepanov1992
BAN USER 8of 8 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
def reverse(s):
l = list(s)
l2 = [c for c in l if c != ' ']
j = 0
for i in range(len(l)  1, 1, 1):
if l[i] == ' ':
continue
else:
l[i] = l2[j]
j += 1
return ''.join(l)

glebstepanov1992
July 23, 2015 Sort an array.
Then for each element a[i] and remained array a[i + 1:] solve two sum problem with sum equal to a[i]
For english you have 26 files, each is responsible for particular character. If word contains this character then it is presented there. "good" is presented in file g,o and d. Each record also contains a field how much particular character have occured in this word.
For good g  1, o  2, d  1. Each file contains word in sorted order. So when you receive and request you find intersection of c1 and c2 in O(n), and so on. Also you check quantity of particular character in the words.
You inrecment both i and j. But what if you can increment only the i and next maximum will be bigger then B1[j]?
 glebstepanov1992 December 27, 2014Please clarify question. How to find rectangle that contains a point?
 glebstepanov1992 December 15, 2014Please could you give some examples.
 glebstepanov1992 December 12, 2014You meant double checking without volatil or with?
 glebstepanov1992 December 12, 2014Please, could you explain vulnerability of volatile&doublechecking initilization usage?
 glebstepanov1992 December 11, 2014Maybe you should use double checking and synchronized section instead of synchronizing whole method.
 glebstepanov1992 December 11, 2014First sort them.
Them calculate cumulative sum.
If some element a[i] is greater than sum + 1 then there is a gap between them. So number sum + 1 cannot be formed  this is the answer.
First sort them.
Them calculate cumulative sum.
If some element a[i] is greater than sum + 1 then there is a gap between them. So number sum + 1 cannot be formed  this is the answer.
def find(a):
sum = 0
for i in range(len(a)):
sum += a[i]
if sum < a[i]  1:
return sum + 1
return sum + 1

glebstepanov1992
December 08, 2014 def check(pattern, text, d):
if len(pattern) == 0 and len(text) == 0:
return True
if len(text) == 0 or len(pattern) == 0:
return False
if pattern[0] in d:
tmp = d[pattern[0]]
if len(tmp) > len(text) or text[:len(tmp)] != tmp:
return False
else:
return check(pattern[1:], text[len(tmp):], d)
else:
for i in range(1, len(text)):
d[pattern[0]] = text[:i]
if check(pattern[1:], text[i:], d):
return True
del d[pattern[0]]
return False

glebstepanov1992
November 26, 2014 Please, could you explain in details how to apply branch and bound approach.
 glebstepanov1992 November 25, 2014All you need it is to found the biggest such palindrone that s = prefix + palindrom.
You can do it in O(N^2), but it is better to use Manacher algorithm for finding all subpalindromes in O(N) and add reversed prefix to the and.
s = prefix + palindrome + reverse(prefix)
Also how to restore numbers, that were used to make a solution.
 glebstepanov1992 November 05, 2014Please, coult you explain your solution?
 glebstepanov1992 November 05, 2014Always shrink occupied seats to median
def count_moves(s):
lst = []
for i in range(len(s)):
if s[i] == 'X':
lst.append(i)
med = len(lst) / 2
left_count = 0
right_count = 0
for i in range(med  1, 1, 1):
left_count += lst[med]  lst[i]  (med  i)
for i in range(med + 1, len(lst)):
right_count += lst[i]  lst[med]  (i  med)
return left_count + right_count

glebstepanov1992
November 05, 2014 def encode(strings):
result = ''
count = str(len(strings))
result += count + ''
for s in strings:
result += str(len(s)) + '' + s
return result
def decode(s):
index = s.find('')
count = int(s[:index])
result = []
s = s[index + 1:]
for i in range(count):
index = s.find('')
count = int(s[:index])
s = s[index + 1:]
result.append(s[:count])
s = s[count:]
return result

glebstepanov1992
October 31, 2014 def encode(strings):
result = ''
count = str(len(strings))
result += count + ''
for s in strings:
result += str(len(s)) + '' + s
return result
def decode(s):
index = s.find('')
count = int(s[:index])
result = []
s = s[index + 1:]
for i in range(count):
index = s.find('')
count = int(s[:index])
s = s[index + 1:]
result.append(s[:count])
s = s[count:]
return result

glebstepanov1992
October 31, 2014 N!/(k1! * k2! * ... * kn!) isnt it? permutation with repeatitions.
 glebstepanov1992 September 04, 2014Algo
1)find first element ')(' from the right side of the string
2)substitute it by '()'
3) count the balance from left to current position
4)add so many close parenthesis as you need to keep the balance
5)Fill the rest with ()
You can use only the one key to,delete or insert an element or any combination of them? If second,i thinnk you should use some spatial data structure like KDtree.
 glebstepanov1992 July 08, 2014I think the answe is product (n  i) where i from 1 to k plus one, where one is 0 of swaps.
 glebstepanov1992 June 25, 2014Give an example,please.
 glebstepanov1992 June 25, 2014Just a zigzag traverse?
 glebstepanov1992 June 25, 2014We can use simple Bubble sort.
public void sort(Node head) {
cur = Head;
cur_next = cur.next;
count = 0;
while(cur != null) {
cur= cur.next;
count++;
}
for(int i = 0;i < count ;i++){
cur = head;
cur_next = cur.next;
for(int j = 0;j < i;j++) {
if(cur.value < cur_next.value){
swap_values(cur,cur_value);
}
}
}
}

glebstepanov1992
June 17, 2014 You meant that final list should be sorted?
 glebstepanov1992 June 17, 2014I think is even number has appeared at least once in [x,y) then mumber will be even.
 glebstepanov1992 June 17, 2014Explain the idea, please
 glebstepanov1992 June 16, 2014Divide it in n parts of equal length , then if some points are equals unioun them . Finally on need to have n points with different values, Than do binary search in each of interval.
 glebstepanov1992 June 07, 2014DFS will be ok in acyclic graphs.
 glebstepanov1992 June 07, 2014Simple, user inorder and preorder traversal to serialize and then deserialize tree.
 glebstepanov1992 June 07, 2014what does it mean transition point?
 glebstepanov1992 June 07, 2014LCA problem?
 glebstepanov1992 June 03, 2014def subsets(target,left,stack,seq,sum):
for i in range(left,len(seq)):
if sum + seq[i] <= target:
stack.append(seq[i])
sum += seq[i]
if sum == target:
print stack
subsets(target,i + 1,stack,seq,sum)
sum = stack.pop()

glebstepanov1992
June 03, 2014 public boolean findCycle(List<Tuple> tuples) {
Map<Character,Character> map = new HashMap();
for(Tuple t : tuples) {
if(map.get(t.getChild() != null) {
return false;
} else {
map.put(t,getParent());
}
return true;
}

glebstepanov1992
May 25, 2014 def find_pivot(array):
left = 0;
right = len(array)  1
cur = (right + left) / 2
while left < cur < right:
cur = (right + left) / 2
if array[cur] < array[right]:
left = cur
elif array[left] < array[cur]:
right = cur
return cur

glebstepanov1992
May 23, 2014 You deen to write serialization. I've written something simular in Java. All you need  it is resolve cyclic reference in order to reject infinite cycle copying. In java You can use identityHashCode and identityHashMap to store each node only once. And that build up list from them. You put the node to the identyty hash Map. Then you looks to pointer. If nodes they are referenced to are in the map  then store their hashcode else put theese node to map and store their hash code.
from
Node next > some other node
to
Node next > 0xAB23FD133
use multidimensional indexed trees like KDtree etc.
Or maintain bit index and make queries with bit operations.
Mutex allow only one thread, semaphore has a counter of threads it can allow to critical section of code.
 glebstepanov1992 May 20, 2014public void visit(Node* root, int& number,int n) {
if(root == null) return;
visit(root>left,number,n);
if(number == n) {
cout<<root>value;
return;
}
number += 1;
visit(root>right,number,n);
}
int number = 0;
visit(root,number,3);
public class PhomeNumbers {
public static List<List<Character>> initData() {
List<List<Character>> list = new ArrayList<List<Character>>();
list.add(new ArrayList<Character>());//0
list.add(new ArrayList<Character>());//1
list.add(new ArrayList<Character>());//2
list.add(new ArrayList<Character>());//3
list.add(new ArrayList<Character>());//4
list.add(new ArrayList<Character>());//5
list.add(new ArrayList<Character>());//6
list.add(new ArrayList<Character>());//7
list.add(new ArrayList<Character>());//8
int j = 0;
for(int i = 0;i < 9;i++) {
for(int k =0;k < 3 && j < 26;k++,j++) {
list.get(i).add((char)('a' + j));
}
}
return list;
}
public static void sequence(int[] numbers,int pos,List<List<Character>> phone,char[] str) {
if(pos == numbers.length) {
for(Character ch : str) {
System.out.print(ch);
}
System.out.println();
return;
}
for(int i = 0;i < phone.get(pos).size();i++) {
str[pos] = phone.get(pos).get(i);
sequence(numbers,pos + 1,phone,str);
}
}
public static void main(String[] args) {
List<List<Character>> list = initData();
int[] numbers = new int[]{1,2};
char[] str = new char[numbers.length];
sequence(numbers,0,list,str);
}
}

glebstepanov1992
April 24, 2014 public class Combinations {
public static List<String> combinations(int n, int k) {
List<String> list = new ArrayList<String>();
boolean flag = false;
List<Integer> cur = new ArrayList<Integer>(k);
for (int i = 0; i < k; i++) {
cur.add(i + 1);
}
list.add(cur.toString());
for (int i = k  1; i >= 0; i) {
while (cur.get(i) < (n  (k  i) + 1)) {
cur.set(i, cur.get(i) + 1);
for (int j = i + 1; j < k; j++) {
cur.set(j, cur.get(j  1) + 1);
}
list.add(cur.toString());
}
}
return list;
}
public static void main(String[] args) {
List<String> list = combinations(5,3);
for(String s : list) {
System.out.println(s);
}
}
}

glebstepanov1992
February 19, 2014 I hav idea how to decide whether we can do it or not. We need to factorize number in prime factors. If among of themat least one prime that is greater than 10  we cannot do it .
 glebstepanov1992 February 19, 2014Use radix sort. And then find first a[i] != a[i + 1]. Complexity is O(n * k) where K = 32. Actually if all numbers are positive it can be done in constant memory.
 glebstepanov1992 February 17, 2014Sort chunks of data unsing radis sort in O(k*n) complexity. Then merge them.
 glebstepanov1992 February 17, 2014Would you give an example.
 glebstepanov1992 February 11, 2014
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 detailoriented 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 hardworking 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 newlycertified 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 ...
RepSusanBrown, Accountant at AMD
I am a resourceful and seasoned Screen Printing Machine Operator with a strong customer service record across a range of ...
RepJeremyBrett, Consultant at Capgemini
Jeremy , a Business Administrator with more than 4 years experience helping companies from various industries plan, organize and control specific ...
Open Chat in New Window
 glebstepanov1992 November 08, 2016