Facebook Interview Question for Software Engineer Interns


Country: United States
Interview Type: Phone Interview




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

Hope this helps

public static void main(String[] args) {
    System.out.print("Enter the limit : ");
    int n = (new Scanner(System.in)).nextInt();
    ArrayList<Integer> list = new ArrayList<>();
    for (int i = 1; i <= n; i++) {
        if (i == findSOC(i)) {
            list.add(i);
        }
    }
    System.out.println(list);
}

private static int findSOC(int i) {
    if (i == 0)
        return 0;
    return findSOC(i / 10) + cube(i % 10);
}

private static int cube(int i) {
    return i * i * i;
}

- PeyarTheriyaa November 09, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
main()
{
int num,,sum=0,i;
scanf("%d",&num);
for(i=num;i!=0;i/=10)
sum+=pow(i%10,3);
if(sum==num)
return(1);
else
return(0);
}

- Anonymous November 09, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

func cubeAllDigits(in number:Int) -> Int {
    var sum = 0
    var left = number
    while left > 0 {
        let x = left % 10
        sum += x * x * x
        left = (left - x) / 10
    }
    return sum
}


print(cubeAllDigits(in: 2)) // 8
print(cubeAllDigits(in: 153)) // 153
print(cubeAllDigits(in: 103)) // 28
print(cubeAllDigits(in: 555555)) // 750

- eugene.kazaev November 15, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Using ruby

def cube_all_digit(input)
	retMe = 0
	input.to_s.each_char do |digit|
		retMe += digit.to_i**3
	end
	return retMe
end

- kusumah November 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def cube_all_digit(input)
	retMe = 0
	input.to_s.each_char do |digit|
		retMe += digit.to_i**3
	end
	return retMe
end

- ahmad.kusumah November 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{ static void Main(string[] args)
{
double res;

for (int i = 1; i < 10; i++)
{
for (int j = 1; j < 10; j++)
{
for (int k = 1; k < 10; k++)
{
res = Math.Pow(i, 3) + Math.Pow(j, 3) + Math.Pow(k, 3);

if ( res == int.Parse(i.ToString() + j.ToString() + k.ToString()) )
{
Console.WriteLine(res);
}
}
}
}
Console.ReadLine();
}}

- amitaiweil December 06, 2018 | 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