## Linkedin Interview Question for Software Engineer / Developers

Country: United States
Interview Type: In-Person

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

string is "a1b" (base 16): return value should be 2587.

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

int convert(char* str, int base){
int value = 0;
int basePower = 1;
// assuming value supplied in str belongs to base
int length = strlen(str);
for(int i = length-1; i >= 0; i++){
if(i == 0 && str[i] == '-'){
value *= -1;
continue;
}
value += (str[i] - '0')*basePower; // this would have worked if digits were // followed by alphabets in ASCII table
basePower *= base;
}
return value;
}

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

do like this
have a loop
int sum=0

iterate
sum=sum*base+str[i]-'0';

where base is the given base

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

for hexadecimals need special care

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

Convert first into binary. From binary, do octal. From binary, do hex. O(n) time each. For octal/hex conversion, create a map such that a["001"] = 1, a["111"]=7 for octal, and for hex b["1111"]="f". O(1) memory, O(n) to convert decimal to binary. Then, O(n) to map the bits to octal or hex using map.

Add a Comment
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.

Learn More

### 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.

Learn More

### Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

### Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More