Goldman Sachs Interview Question
Developer Program EngineersCountry: India
Interview Type: Written Test
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static boolean denomination(int numb)
{
int a=5,b=3;
boolean canMakeAmount = false;
while(numb >0)
{
numb = numb-a;
numb = numb%b;
if(numb == 0)
canMakeAmount = true;
if(numb < a && numb < b)
break;
}
return canMakeAmount;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
System.out.println(denomination(23));
System.out.println(denomination(16));
System.out.println(denomination(10));
}
}
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static boolean denomination(int numb)
{
int a=5,b=3;
boolean canMakeAmount = false;
while(numb >0)
{
numb = numb-a;
numb = numb/b;
if(numb == 0)
canMakeAmount = true;
if(numb < a && numb < b)
break;
}
return canMakeAmount;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
System.out.println(denomination(23));
System.out.println(denomination(16));
System.out.println(denomination(10));
}
}
public class Test {
private static boolean findDenomination(int num)
{
int tempNum = num;
while(tempNum > 0)
{
tempNum = tempNum - 3;
if(tempNum >=5 && tempNum%5 == 0)
{
return true;
}
}
return false;
}
public static void main(String[] args) {
System.out.println(findDenomination(110));
}
}
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static boolean pol(int m){
if(m<0)
return false;
if(m==0)
return true;
return pol(m-5)||pol(m-3);
}
public static void main (String[] args) throws java.lang.Exception
{
int m=107;
boolean b=pol(m);
if(b)
System.out.println("yes");
else
System.out.println("No");
}
}
public class sample {
public static void main(String[] args)throws Exception
{
int m=28;
System.out.println(count(m));
}
static boolean count(int m)
{
if(m<=0)
{
return false;
}
else
{
int modFive = m%5;
if(m%3==0 || modFive==0){
return true;
}
else if(modFive >= 3)
{
if((modFive)%3 == 0)
return true;
}
}
return false;
}
}
- Pro April 28, 2015