Facebook Interview Question for Software Developers


Team: Community Operations
Country: United States




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

def fun(temp,k,i,l):
	#swap l[i] and temp
	swap_val=l[i]
	l[i]=temp
	temp=l[i]
	if(temp==None):
		return l
	else:
		return fun(temp,k,(i+k)%len(l),l)

- nikhil19kekan December 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
 * @param {number[]} nums
 * @param {number} k
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var rotate = function(nums, k) {
    let len = nums.length
    let portion = nums.splice(len - (k%len), len)

    nums.unshift(...portion)
};

- dtallinterviewee December 04, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void rotate(int in[], int l, int k){
	int cur = k%l;
	while(cur != 0){
		swap(in, 0, cur);
		cur = (cur+k)%l;
	}
}

- sushachawal December 08, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Whoops, forgot to include the swap function

void rotate(int in[], int l, int k){
	int cur = k%l;
	while(cur != 0){
		int temp = in[0];
		in[0] = in[cur];
		in[cur] = temp;
		cur = (cur+k)%l;
	}
}

- sushachawal December 08, 2018 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

function rotate(inp, l, k){
  let cur = parseInt(l - (k%l));
  let i=0;
	while(cur < l){
		let temp = inp[i];
		inp[i] = inp[cur];
		inp[cur] = temp;
		cur++;
    i++;
	}
  cur = k;
  key = parseInt(l - (k%l));
  key2 = key;
  while(cur < key){
		let temp = inp[key2];
		inp[key2] = inp[cur];
		inp[cur] = temp;
		cur++;
    key2++;
	}
  console.log(inp);
}

let arr = [1,2,3,4,5,6]; 
rotate(arr,arr.length,2);

- maan December 12, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

function rotate(inp, l, k){
	let cur = parseInt(l - (k%l));
  let i=0;
	while(cur < l){
		let temp = inp[i];
		inp[i] = inp[cur];
		inp[cur] = temp;
    
		cur++;
    i++;
	}
  cur = k;
  key = parseInt(l - (k%l));
  let key2 = key;
  while(cur < key){
		let temp = inp[key2];
		inp[key2] = inp[cur];
		inp[cur] = temp;
		cur++;
    key2++;
	}
  inp = inp.filter(function( element ) {
     return element !== undefined;
  });
  console.log(inp);
}

let arr = [1,2,3,4,5,6,7]; 
rotate(arr,arr.length,2);

- maan December 12, 2018 | Flag


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