codewarrior
BAN USER 0of 0 votes
AnswersGiven two strings, return true if they are one edit away from each other, else return false. An edit is insert/replace/delete a character.
 codewarrior in United States
Ex. {"abc","ab"}>true, {"abc","adc"}>true, {"abc","cab"}>false Report Duplicate  Flag  PURGE
Amazon SDE1  0of 0 votes
AnswersFind the total number of connected components in a graph (there can be forests)
 codewarrior in United States Report Duplicate  Flag  PURGE
Amazon SDE1
Good solution and clear explanation.
 codewarrior August 25, 20151. Calculate ceil(25%) from size of the list, let this be m. m customers with highest spending receive msg1, m customers with least spending receive msg2, (nm) customers receive msg3.
2. use quick select to find i = index of m highest customers, j = index of m lowest customers  these 2m customers receive msg's 1 and 2
3. rest of the customers from i+1 to j1 receive msg 3
Congrats on providing the worst ever description of a question.
 codewarrior August 23, 2015null
 codewarrior August 12, 2015@payal:
what do these methods do? are they similar to adding/removing facebook/linkedin relationships?
@SycophantEve:
Tried your solution with following input:
a = [{5,1},{1,3},{4,10}]
interv = {2,12}
expected output: [{5,12}]
Your solution gives output as [{5,12}{1,3}]
Can we ban this jerk's IP?
 codewarrior July 08, 2015Cant this be improved using a trie
 codewarrior April 20, 2015can you explain a bit more clearly? What does MathedChars() do?
 codewarrior April 20, 2015@kurobi:
Not necessary. You find the root, and then you traverse based on the ordering of the children in the List. A List, as you should know, is an ordered data structure.
Doesn't this return true for input 'hhire'?
 codewarrior November 07, 2013public static boolean wordBrute(String word, int index) {
if(index>=word.length())
return true;
int[] hist = new int[4];
int i;
outerLoop:
for(i=index;i<word.length();i++) {
char histChar = word.charAt(i);
switch(histChar) {
case 'h': {
hist[0]++;
break;
}
case 'i': {
if(check(hist,1))
return false;
hist[1]++;
break;
}
case 'r': {
if(check(hist,2))
return false;
hist[2]++;
break;
}
case 'e': {
if(check(hist,3))
return false;
while(i<word.length() && word.charAt(i) == 'e' ) {
i++;
hist[3]++;
}
break outerLoop;
}
default:
return false;
}
}
int prev = hist[0];
for(int j=1;j<hist.length;j++) {
if(hist[j] != prev)
return false;
prev = hist[j];
}
return true && (wordBrute(word,i));
}
public static boolean check(int[] hist,int index) {
return hist[index1] == 0;
}
 codewarrior November 07, 2013public static void rev(Node node,Node prev) {
if(node == null) {
list.headNode = prev;
return;
}
Node temp = node.next;
node.next = prev;
rev(temp,node);
}
Call this with
rev(list.headNode,null);
that was awesome. some explanation would have helped though!
 codewarrior February 25, 2013public static void compressString(String inp) {
StringBuilder out = new StringBuilder();
int count = 1;
for(int i=0;i<inp.length();i++)
{
if(i<inp.length()1 && inp.charAt(i) == inp.charAt(i+1)) {
count++;
continue;
}
out.append(inp.charAt(i));
if(count>1)
out.append(count);
count=1;
}
System.out.println(out.toString());
}

codewarrior
February 19, 2013 This is O(n2) right?
 codewarrior February 19, 2013@Abakumoff:
Vik never said the first step is not O(N). It takes N/2 iterations for the fast pointer to reach the end of the list. Time complexity is O(N/2) which is O(N). I don't see why you should do a downvote.
Sort the array in descending order 
T(N) = O(NlgN) and S(N) = O(1)
Lookup in a set has a worst case complexity of O(N) and an average case of O(1).
 codewarrior February 15, 2013Did you even understand what was asked in the question?
 codewarrior February 15, 2013correct algorithm, but poorly written.
 codewarrior February 08, 2013
Repcrystalblibby, Analyst at Achieve Internet
By professional i am teacher. Successfully supervised and assisted students, grade artwork, encouraged creativity and new technique.Familiar with art ...
Open Chat in New Window
Straightforward and simple. awesome.
 codewarrior August 30, 2015