## Adobe Interview Question for SDE-2s

Country: United States

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````public static int calcString(String str){

int sum =0;

Pattern p = Pattern.compile("[+-]?\\d+");
Matcher m = p.matcher(str);

while (m.find()) {
sum += Integer.parseInt(m.group().trim());
}
return sum;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

In Java, I would something like:

``````public static int sum(String expression)
{
int sum = 0;
if(expression.length() == 0)
return 0;

for(int i = 0; i < expression.length() - 1; i = i + 2)
{
int value = Character.getNumericValue(expression.charAt(i));
char operator = expression.charAt(i + 1);
if(operator.equals("+"))
sum = sum + value;
else
sum = sum - value;

return sum;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

It actually took me a while to finally go with the following solution:

``````public static int calcString(String str){

int sum =0;

Pattern p = Pattern.compile("[+-]?\\d+");
Matcher m = p.matcher(str);

while (m.find()) {
sum += Integer.parseInt(m.group().trim());
}
return sum;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int strsum(const char* str) {
int sum = 0;
int num = 0;
int sign = '+';
int c;
while(c = *str++) {
switch(c) {
case '+':
case '-':
sum = (sign == '+'? sum + num: sum - num);
sign = c;
num = 0;
break;
default:
num = num * 10 + (c - '0');
}
}
return (sign == '+'? sum + num: sum - num);
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int strsum(const char* str) {
int sum = 0;
int num = 0;
int sign = '+';
int c;
while(c = *str++) {
switch(c) {
case '+':
case '-':
sum = (sign == '+'? sum + num: sum - num);
sign = c;
num = 0;
break;
default:
num = num * 10 + (c - '0');
}
}
return (sign == '+'? sum + num: sum - num);
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int strsum(const char* str) {
int sum = 0;
int num = 0;
int sign = '+';
int c;
while(c = *str++) {
switch(c) {
case '+':
case '-':
sum = (sign == '+'? sum + num: sum - num);
sign = c;
num = 0;
break;
default:
num = num * 10 + (c - '0');
}
}
return (sign == '+'? sum + num: sum - num);
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int strsum(const char* str) {
int sum = 0;
int num = 0;
int sign = '+';
int c;
while(c = *str++) {
switch(c) {
case '+':
case '-':
sum = (sign == '+'? sum + num: sum - num);
sign = c;
num = 0;
break;
default:
num = num * 10 + (c - '0');
}
}
return (sign == '+'? sum + num: sum - num);
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
{"ft_lang_label":"__label__en","ft_lang_prob":0.6008674,"math_prob":0.9980373,"size":457,"snap":"2021-31-2021-39","text_gpt3_token_len":130,"char_repetition_ratio":0.14128035,"word_repetition_ratio":0.0,"special_character_ratio":0.32166302,"punctuation_ratio":0.21839081,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9985976,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-22T01:22:17Z\",\"WARC-Record-ID\":\"<urn:uuid:048b24d9-aba7-404f-9088-7e67ca0f8f53>\",\"Content-Length\":\"37345\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:746b011e-243e-404a-9d17-2b6ddb40a276>\",\"WARC-Concurrent-To\":\"<urn:uuid:564916e4-76e1-4f3d-b374-c60031a41968>\",\"WARC-IP-Address\":\"142.250.73.211\",\"WARC-Target-URI\":\"https://www.careercup.com/question?id=4842971357773824\",\"WARC-Payload-Digest\":\"sha1:RAPDOOULC6TIBRPM77462PQROSEH5YVJ\",\"WARC-Block-Digest\":\"sha1:E2DWQGYSVVFTDQ4NMNXJXRCMMMTVTQ5L\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780057303.94_warc_CC-MAIN-20210922011746-20210922041746-00215.warc.gz\"}"}