GSheld
BAN USER
Questions (3)
Comments (2)
Reputation 100
- 0of 0 votes
AnswersPrint a 2D array in spiral order.
- GSheld in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
import java.util.StringBuilder;
public class Encoding {
protected static StringBuilder encodedStr = new StringBuilder();
private static void encodeStr(char[] c, int start) {
int count = 1;
if (start > c.size -1) {
return;
}
encodedStr.add(c[start]);
while (c[count + start - 1] == c[count + start]) {
count++;
}
encodedStr.add(count);
encodeStr(c, start+count);
}
public static String encodeStr(String str) {
encodeStr(str.toCharArray(), 0);
return encodedStr.toString();
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
This was my attempt in java:
- GSheld January 10, 2014