Interview Question for Front-end Software Engineers


Country: United States




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

I am not sure about the exact problem.

But from example it seems that you have to write an algorithm, with all permutation and combinations whose sum of digits is given number.

- Nitin Gupta January 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This type of problem is typically known as Partition problem. The number of partitions of a number grows exponentially. I read somewhere that Its an NP-Complete problem. Here are few references that you can check to know more about it.

math.stackexchange.com/questions/217597/number-of-ways-to-write-n-as-a-sum-of-k-nonnegative-integers

en.wikipedia.org/wiki/Partition_%28number_theory%29#Intermediate_function

stackoverflow.com/questions/400794/generating-the-partitions-of-a-number#400810

Some of these links will provide you with the implementation in some lang. You can go through the math for wikipedia link.

- Coder January 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function countSteps(n){
	var counts = 0;
	function partition(arr, last ,m){
		var tempArr;
		if(m > 1){
			for(var i = last || 1; i <= m/2; i++){
				tempArr = arr.slice(0);
				if(m-i > i){
					tempArr.push(i);

					if(m-i > 1){
						partition(tempArr.slice(0), i, m-i);
					}

					tempArr.push(m-i);
				}else if(m-i == i){
					tempArr.push(i);
					tempArr.push(m-i);
				}else{
					return
				}
			}
		}else{
			tempArr = arr.slice(0);
			tempArr.push(m);
		}

		if(tempArr){
			counts += 1;
			console.log(tempArr);	
		}
	}
	partition([], null, n);
	return counts;
}

- qbaty.qi February 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

var all = [];

function findStep(n) {
if (n===1){
console.log(1);
} else {
_findIt(n, []);
}

all.sort();
var prev = [];
for(var i=0; i<all.length; i++){
var curr = all[i];
if (curr.join() == prev.join()){
all.splice(i,1);
i--;
} else {
prev = curr;
}
}

console.log(all);
console.log(all.length);
}

function getSum (arr){
return arr.reduce(function(a,b){
return a+b;
},0);
}

function _findIt(n, result){
var currentSum = getSum(result);
for(var i = 1; i <= n; i++){
var nextSum = currentSum + i;
if (nextSum === n){
result.push(i);

result.sort();
//console.log(result.join());
all.push(result);
return;
} else {
var newArray = result.slice(0);
newArray.push(i);
_findIt(n, newArray);
}
}
}

findStep(4)

- Pavel October 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

48 ways

- Rohit Garg October 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function findSteps(n){
	var counter = 1 ;
	for(var i = 1 ; i < n ; i++){
		for(var j = i; j < n ; j++){
			if(i+j <= n){
				counter++;
			}
		}
	}	
	console.log(counter);
}

findSteps(2);

- Saloni Chacha November 13, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function findSteps(n) {
	let count = 0
	// think of 'd' as number of digits
	for (let d = n; d > 0; d--) {
		count += (n - d - Math.ceil(n/d) + 2)
	}
	return count
}

- cmw228 September 17, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function findSteps(n) {
	let count = 0
	// think of 'd' as number of digits
	for (let d = n; d > 0; d--) {
		count += (n - d - Math.ceil(n/d) + 2)
	}
	return count
}

- cmw228 September 17, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function findSteps(n) {
	let count = 0
	// think of 'd' as number of digits
	for (let d = n; d > 0; d--) {
		count += (n - d - Math.ceil(n/d) + 2)
	}
	return count
}

- cmw228 September 17, 2017 | Flag Reply


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