## Interview Question for Android Engineers

• 0

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))``````

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))

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))``````

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");
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{
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;
}``````

}

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

{{
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;
}
}}

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;
}``````

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

``test``

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);
}
}``````

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));
}``````

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));

}``````

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));}

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));

}``````

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));

}``````

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;
}``````

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;``````

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;``````

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);
}
}

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);
}
}``````

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);
}
}``````

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);
}
}

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]

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.

### 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.