Microsoft Interview Question for SDE1s

Team: Office365
Country: India
Interview Type: In-Person

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

0.5 is hardly any integer... Was it doubles or decimals?

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

String.valueOf()

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

String.valueOf(<integer value>)

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

std: :string s = std: :to_string(<int value>)

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

"0"

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

If you want to do this without libraries, it isn't easy for float numbers because even something like 20.04 will turn into 20.03999999999
If someone can find a way to fix the lines with my 'problems with rounding here' comments, this algorithm will work:

``````function toStr(num) {
var n = Math.abs(num);
var intPart = Math.floor(n);
var floatPart = n - intPart; // problems with rounding here

var intResult = [];
while (intPart > 0) {
intResult.unshift(String(intPart % 10));
intPart = Math.floor(intPart / 10);
}

var floatResult = [];
while (floatPart > 0) {
floatPart *= 10;
var floatDigit = Math.floor(floatPart);
if (floatDigit >= 1) {
floatResult.push(String(floatDigit));
floatPart -= floatDigit;  // problems with rounding here
} else {
floatResult.push('0');
}
}
var result = intResult.slice();
if (floatResult.length > 0) {
result.push('.');
Array.prototype.push.apply(result, floatResult);
}
if (num < 0) {
result.unshift('-');
}
return result;
}``````

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