wyu277
BAN USER
- -4of 4 votes
AnswersShorten a List of Strings.
- wyu277 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 0of 2 votes
AnswersDesign a Black-Jack poker game
- wyu277 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Object Oriented Design - 4of 4 votes
AnswersGive an 2d-characters Grid, char[][] A, and a dictionary, List<String> dict. Search all possible words in the 2d-Grid.
- wyu277 in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm - 1of 1 vote
AnswersMinesweeper question: Given an n x m grid holding individual mine co-ordinates, identify all of the mine clusters. A mine cluster is the largest collection of neighboring mines.
- wyu277 in United States
Example input:
0 1 2 3
---------
0|0|1|0|1
1|0|0|1|1
2|0|0|0|0
3|1|1|0|0
Expected output:
[cluster 1] (0,1),(1,2),(1,3),(0,3)
[cluster 2] (3,0),(3,1)| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm
First, the length of S1 and S2 should equal.
It is ez to solve by duplicate s1 or s2 like s2 = s2+s2:
e.g S1="amazon" S2="azonam"
Assuming we are duplicating S2:
S2="azonamazonam";
Then, we can scan S2, find whether S2 contains S1.
public static boolean isRotated(String s1, String s2) {
if (s1.length()!=s2.length())
return false;
int len = s1.length();
// double String "s2";
s2 = s2+s2;
for (int i=0;i<len;i++) {
if (s2.substring(i,i+len).equals(s1))
return true;
}
return false;
}
The time complexity should be O(n), space complexity O(1);
}
- wyu277 August 17, 2014First, the length of S1 and S2 should equal.
It is ez to solve by duplicate s1 or s2 like s2 = s2+s2:
e.g S1="amazon" S2="azonam"
Assuming we are duplicating S2:
S2="azonamazonam";
Then, we can scan S2, find whether S2 contains S1.
public static boolean isRotated(String s1, String s2) {
if (s1.length()!=s2.length())
return false;
int len = s1.length();
// double String "s2";
s2 = s2+s2;
for (int i=0;i<len;i++) {
if (s2.substring(i,i+len).equals(s1))
return true;
}
return false;
}
The time complexity should be O(n), space complexity O(1);
}
- wyu277 August 17, 2014It could ez solve by using the functions of StringBuilder:
insert(offset,char)
append(char)
static String reverseWords(String s) {
if (s==null||s.length()==0)
return "";
StringBuilder result = new StringBuilder();
int j=0; // position of last [comma,space,numbers]
for (int i=0;i<s.length();i++) {
char c = s.charAt(i);
if (c==' '||Character.isDigit(c)||c==','){
result.append(c);
j=i+1;
} else result.insert(j, c);
}
return result.toString();
}
}
- wyu277 August 05, 2014
RepPennyRMullins, xyz at Aspire Systems
I am a creative Interior Designer with 2+ years of experience building customized solutions for residential and commercial clients. Intuitively ...
Repsonjamramos45, Graphics Programmer at CGI-AMS
I am a strong writer with a passion for story-telling who has extensive experience of writing literary compositions, articles, reports ...
RepJaneBraun, Associate at ASAPInfosystemsPvtLtd
Hi, I am Jane From York,PA.My goal is to create a life that I don’t want to ...
Repmarisamsan7, Cloud Support Associate at ADP
Hi, I am Photoengraver from an CO,USA. I am a girl with a strong desire to travel the world ...
Rephoychrista, Blockchain Developer at ASU
Worked with Clients to guide them through the event details about copier leasing companies and served as their personal coordinator ...
RepLornaEllis, Android test engineer at Abax Techno Solutions
I am Lorna Job estimator, also known as cost planners, who are responsible for estimating the costs of a planned ...
- wyu277 September 17, 2014