Interview Question for Android Engineers


Country: India
Interview Type: In-Person




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

import math as m

def recursiveFunction(n):

    if n == 0:
        return 0

    if n == 1:
        return 1

    s = int(m.sqrt(n))

    return recursiveFunction(n - s*s) + 1

print(recursiveFunction(6))

- Anonymous May 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

import math as m

def recursiveFunction(n):

if n == 0:
return 0

if n == 1:
return 1

s = int(m.sqrt(n))

return recursiveFunction(n - s*s) + 1

print(recursiveFunction(6))

- Anonymous May 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

import math as m

def recursiveFunction(n):

    if n == 0:
        return 0

    if n == 1:
        return 1

    s = int(m.sqrt(n))

    return recursiveFunction(n - s*s) + 1

print(recursiveFunction(6))

- Chandni May 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public class CareerCup {
	static ArrayList<Integer> elements = new ArrayList<>();
	static int inputValue;
	public static void main(String args[]){
		System.out.println("Enter the number");
		Scanner reader = new Scanner(System.in); 
		inputValue = reader.nextInt();
		FindNumbers(inputValue);
		System.out.println("Count is: " + elements.size());
		System.out.print("numbers are: ");
		for (int i = 0; i < elements.size(); i++) {
		    int value = elements.get(i);
		    System.out.print(value + ",");
		}
	}
	
	public static void FindNumbers(int value){
		if(check()){
			System.out.println("Finished finding numbers");
		}else{
			elements.add(GetNearestSquare(value));
			FindNumbers(inputValue - getSum());
		}
	}
	
	private static int getSum() {
		int len = elements.size();
		int sum = 0;
		for(int i=0; i<len; i++){
			int n = elements.get(i);
			sum = n*n + sum;
		}
		return sum;
	}

	public static boolean check(){
		int len = elements.size();
		int sum = 0;
		for(int i=0; i<len; i++){
			int n = elements.get(i);
			sum = n*n + sum;
		}
		if(sum == inputValue){
			return true;
		}
		else{
			return false;
		}
	}
	public static int GetNearestSquare(int num){
		int k = 0;
		if(num == 1)
			k = 1;
		else{
			for(int i=1; i<=num; i++){
				if(i*i > num){
					k = i - 1;
					break;
				}
			}
		}
		return k;
	}

}

- nagakrishna555 May 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{
public static int findQuads(int x){
int i=0,r;
while (x>0){
r=(int)(Math.sqrt((double)x));
x=x-r*r;
System.out.println("x: "+x+", r: "+r );
i++;
}
return i;
}
}}

- Julian May 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int findQuads(int x){
		int i=0,r;
		while (x>0){
			r=(int)(Math.sqrt((double)x));
			x=x-r*r;
			System.out.println("x: "+x+", r: "+r );	
			i++;
		}
		return i;
	}

- Julian May 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

test

- shashi kumar May 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.eb.corealgo;

public class SquareValue {

	int finalCount=0;;
	public int getNumberSquareCount(int number){
		
		int foundIndexValue=-1;
		int repeatIndexValue=-1;
		boolean isComplete=false;
		int repeatNumber=-1;
		
		for(int i=1;i<=number;i++){
				 int doubleVal=i*i;
				 if(number==doubleVal){
					foundIndexValue=i;
					isComplete=true;
					break;
				}
				if(doubleVal>number){
					
					foundIndexValue=i;
					break;
				}
				if(doubleVal<number){
					
					foundIndexValue=i;
				}
			
		}
		
		if(foundIndexValue!=-1){
			repeatIndexValue=foundIndexValue-1;
			finalCount++;
			
		}
		repeatNumber=number-repeatIndexValue*repeatIndexValue;
		if(repeatNumber>0 && repeatNumber!=1 && !isComplete){
			
			//call again
			foundIndexValue=-1;
			getNumberSquareCount(repeatNumber);
		}
		else if(!isComplete){
			finalCount++;
		}
		
		return finalCount;
	}
	
	//test
	public static void main(String args[]){
		
		SquareValue v=new SquareValue();
		v.getNumberSquareCount(11);
	}
}

- shashi kumar May 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is the java version

public static int getCount(int n) {
		if (0 == n)
			return 0;
		if (1 == n)
			return 1;
		int sqrt = (int) Math.sqrt(n);
		return 1 + getCount(Math.abs(n - sqrt * sqrt));
	}

- Raj May 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int check (int );
int main(int argc, char *argv[])
{
 int number,i;
 printf("Enter the number \n");
 scanf("%d",&number);
 int series[10];
    printf("The num is\n");
    for(i=0;;i++)
    {
        if(number>1)
        {
            series[i]=check(number);
            printf("%d^2 +",series[i]);
            number = (number - series[i]*series[i]);

        }
        else if(number == 1)
        {
            printf("1^2");
            number = 0;
        }
        else
            break;

    }
 return 0;
}

int check (int num)
{
    return ( (int) sqrt(num));

}

- Piyush Upadhyay May 31, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int check (int );
int main(int argc, char *argv[])
{int number,i;
printf("Enter the number \n");
scanf("%d",&number);
int series[10];
printf("The num is\n");
for(i=0;;i++)
{
if(number>1)
{series[i]=check(number);
printf("%d^2 +",series[i]);
number = (number - series[i]*series[i]);}
else if(number == 1)
{printf("1^2");
number = 0;}
else break;}
return 0;
}
int check (int num)
{return ( (int) sqrt(num));}

- Piyush Upadhyay May 31, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int check (int );
int main(int argc, char *argv[])
{
 int number,i;
 printf("Enter the number \n");
 scanf("%d",&number);
 int series[10];
    printf("The num is\n");
    for(i=0;;i++)
    {
        if(number>1)
        {
            series[i]=check(number);
            printf("%d^2 +",series[i]);
            number = (number - series[i]*series[i]);

        }
        else if(number == 1)
        {
            printf("1^2");
            number = 0;
        }
        else
            break;

    }
 return 0;
}

int check (int num)
{
    return ( (int) sqrt(num));

}

- Anonymous May 31, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int check (int );
int main(int argc, char *argv[])
{
 int number,i;
 printf("Enter the number \n");
 scanf("%d",&number);
 int series[10];
    printf("The num is\n");
    for(i=0;;i++)
    {
        if(number>1)
        {
            series[i]=check(number);
            printf("%d^2 +",series[i]);
            number = (number - series[i]*series[i]);

        }
        else if(number == 1)
        {
            printf("1^2");
            number = 0;
        }
        else
            break;

    }
 return 0;
}

int check (int num)
{
    return ( (int) sqrt(num));

}

- dRunk_Knight May 31, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void decompose(int n) {
vector<int> result = {};
while(n) {
	int odd = 1;
	int count = 1;
	while(n>0) {
		n -= odd;
		odd+=2;
		count++;
	}
	if(n == 0) {
		result.push(count);
	} else {
		n += odd;
		result.push(count-1);
	}
}

for(int i = 0; i < result.length; i++) {
	cout << result[i] << "^" << 2 << +;
}

cout << endl;
}

- Hari May 31, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

vector<int> result = {};
while(n) {
	int odd = 1;
	int count = 1;
	while(n>0) {
		n -= odd;
		odd+=2;
		count++;
	}
	if(n == 0) {
		result.push(count);
	} else {
		n += odd;
		result.push(count-1);
	}
}

for(int i = 0; i < result.length; i++) {
	cout << result[i] << "^" << 2 << +;
}

cout << endl;

- Hari May 31, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

vector<int> result = {};
while(n) {
	int odd = 1;
	int count = 1;
	while(n>0) {
		n -= odd;
		odd+=2;
		count++;
	}
	if(n == 0) {
		result.push(count);
	} else {
		n += odd;
		result.push(count-1);
	}
}

for(int i = 0; i < result.length; i++) {
	cout << result[i] << "^" << 2 << +;
}

cout << endl;

- Hari May 31, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.santosh;

public class Sample {
public static void main(String[] args)
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
sqrt(6);
}

static int sqrt(double num) {
if (num == 1) {
System.out.println(1);
return 1;
}
if (num == 0) {
return 1;
}
Integer sqrt = (int) Math.sqrt(num);
System.out.println(sqrt);
num = num - sqrt * sqrt;
return sqrt(num);
}
}

- Sandy June 01, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.santosh;

public class Sample {
	public static void main(String[] args)
			throws ClassNotFoundException, InstantiationException, IllegalAccessException {
		sqrt(6);
	}

	static int sqrt(double num) {
		if (num == 1) {
			System.out.println(1);
			return 1;
		}
		if (num == 0) {
			return 1;
		}
		Integer sqrt = (int) Math.sqrt(num);
		System.out.println(sqrt);
		num = num - sqrt * sqrt;
		return sqrt(num);
	}
}

- Sandy June 01, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.santosh;

public class Sample {
	public static void main(String[] args)
			throws ClassNotFoundException, InstantiationException, IllegalAccessException {
		sqrt(6);
	}

	static int sqrt(double num) {
		if (num == 1) {
			System.out.println(1);
			return 1;
		}
		if (num == 0) {
			return 1;
		}
		Integer sqrt = (int) Math.sqrt(num);
		System.out.println(sqrt);
		num = num - sqrt * sqrt;
		return sqrt(num);
	}
}

- Sandy June 01, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.santosh;

public class Sample {
public static void main(String[] args)
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
sqrt(6);
}

static int sqrt(double num) {
if (num == 1) {
System.out.println(1);
return 1;
}
if (num == 0) {
return 1;
}
Integer sqrt = (int) Math.sqrt(num);
System.out.println(sqrt);
num = num - sqrt * sqrt;
return sqrt(num);
}
}

- santosh.b June 01, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its edit of 1-0 Knapsack problem

Formula -

if j < sql[i - 1]
dp[i, j] = dp[i -1, j]
elif sq[i - 1] % j == 0
dp[i, j] = sq[i - 1] / j
else
dp[i, j] = min(dp[i - 1, j], (sq[i - 1] / j) + dp[i - 1, j - sq[i - 1] % j]

- om471987 June 12, 2016 | 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