直接海投 software engineer - flash blade ,收到purestorage的OA。看地里的面经,都是8或9或12题,自行考古,很详细。我收到的测试为dev tools,只有两
题,只有两题,只有两题,比较简单。。。
一道是count how many substring can be a palindrom in a input string, leetcode原题
一道是,给一个文件有历史访问记录,每一行为一条记录,提起记录中有过同一时间多次访问的timestamp
找工作开始得比较晚,到现在还在折腾。转行伤不起,继续加油。
The question was about checking if the given sequence of events is valid. The conditions are:
The order of release should be reverse of aquiring(stack)
A locked lock can not be aquired again
A lock has to be locked before releasing
There should be no dangling locks
// Complete the check_log_history function below.
static int check_log_history(List<String> events) {
HashSet<Integer> hs = new HashSet();
Stack<Integer> st = new Stack();
for(int i = 0; i < events.size(); i++){
String e = events.get(i);
String name = e.split(" ")[0];
int num = Integer.parseInt(e.split(" ")[1]);
if(name.equals("ACQUIRE")){
if(hs.contains(num)){
return i+1;
}
st.push(num);
hs.add(num);
}else{
if(!hs.contains(num) || st.peek() != num){
return i+1;
}
st.pop();
hs.remove(num);
}
}
return st.empty() ? 0 : events.size()+1;
}
Find the score for each number, you got points for:
+1 for number divisible by 7
+2 for even digits
+4 for each 9
+5 for 2 consecutive 1 and +5 for each consecutive followine one
+N2 for every continous sequnce of the form 123 or 4567 of length N
This code fails for just one case, not sure why!
// Complete the compute_number_score function below.
static int compute_number_score(int number) {
if(number==0){
return 2;
}
// System.out.println( getDigitWiseScore(number) + " " + countConsecutiveOnes(number) +" " +get(number));
return getDigitWiseScore(number) + countConsecutiveOnes(number) +get(number);
}
public static int getDigitWiseScore(int num){
int score = 0;
if(num%7==0) score+=1;
while(num>0){
int d = num%10;
if(d==9) score+=4;
if(d%2==0) score+=2;
num = num/10;
}
return score;
}
public static int countConsecutiveOnes(int num){
int score =0;
int currentOnes = 0;
while(num > 0 ){
int d = num%10;
num = num/10;
if(d!=1 && currentOnes > 1 ){
score+=5;
score += (currentOnes-2)*5;
currentOnes = 0;
}
if(d==1){
currentOnes++;
}
}
if(currentOnes> 1){
score+=5;
score += (currentOnes-2)*5;
}
return score;
}
public static int getSeq(int num){
String s = Integer.toString(num);
int score=0;
int pointer = 1;
int current = 1;
int previous = s.charAt(0);
while(pointer< s.length()){
if(s.charAt(pointer) == previous){
current++;
previous++;
} else if( current > 1 && s.charAt(pointer) != previous+1 ){
score = score+ (current*current);
current =01;
score = score+1;
} else{
score = score+1;
}
previous = s.charAt(pointer);
pointer++;
}
return score;
}
public static int get(int num) {
int x=0, count=1;
List<Integer> store = new ArrayList<>();
String s = Integer.toString(num);
while(x<s.length()-1) {
if (s.charAt(x)+1 == s.charAt(x+1)){
count ++;
x++;
}
else {
x++;
store.add(count);
count = 1;
}
}
store.add(count);
int score = 0;
for(Integer i: store){
score += i*i;
}
return score;
}