Deshaw Inc Interview Question for Software Engineer / Developers






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

I dont think such a number will exist. According to the problem definition the numbered formed by first two digits must be divisible by 2 and and the number formed by the first five digits must be divisible by 5. Only case it can happen is first digit must be a zero which should not be the case according to problem statement.

Well if my understanding of the problem is wrong please correct me.

- kapil August 15, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think this is the algorithm to do it. I think they just want you to come up with the algorithm. This is a typical permuation algorithm with a few tweaks.


string numberStr = "123456789";

print (numberStr, "");

void print(string numberStr, string result){
if (result.length() >= 9)
{
cout << result << endl;
}
else{

for (int i = 0; i < numberStr.length(); ++i)
{
int len = result.length();
char chr = numberStr[i];

int n = (atoi(result) * 10) + atoi(chr);
if ((n%(len + 1)) == 0)
{
result += chr;
remove chr from numberStr
print (numberStr, result);
}

}
}
}

- Khoa August 15, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

381654729 is the number. This question is part of USA Math Talent Search Problems. You can google it:
http://www.google.com/search?q=381654729

- B0Rg October 23, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

but the number does not satisfy the condition that first two numbers formed to be divisible by 2

- thinker July 25, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

B0Rg on October 23, 2006 is correct. 381654729 is not the only number though. Execute the following program and it will list all such elements

import java.util.*;
public class Selection {

 private ArrayList<Integer> WorkingSet = new ArrayList<Integer>(); 
 private ArrayList<Integer> TempSet = new ArrayList<Integer>();
 
 public static void main(String[] args)
 {
	Selection sel = new Selection();
	sel.getTheNum();
 }
 
 public void getTheNum()
 {
	this.WorkingSet.add(1);
	this.WorkingSet.add(2);
	this.WorkingSet.add(3);
	this.WorkingSet.add(4);
	this.WorkingSet.add(5);
	this.WorkingSet.add(6);
	this.WorkingSet.add(7);
	this.WorkingSet.add(8);
	this.WorkingSet.add(9);
	
	try 
	{
		for (int i = 2; i <= 9; i++)
		{
			Iterator<Integer> iter = this.WorkingSet.iterator();
			System.out.println("Elements after iteration no-" + i + " " + WorkingSet.toString());
			Thread.sleep(2000);
			while(iter.hasNext())
			{
				Integer num = iter.next();
				num *= 10; 
				for (int j = 1; j <= 9; j++)
				{				
					num += j;
					if ((num % i) == 0)
						this.TempSet.add(num);
					num -= j;
				}
				
			}
			this.WorkingSet.clear();
			this.WorkingSet.addAll(TempSet);
			this.TempSet.clear();
		}
		System.out.println("Elements after last iteration no-" + WorkingSet.toString());
	}
	catch(InterruptedException ie)
	{
				
	}	
 }
 
}

- Anonymous September 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

B0Rg on October 23, 2006 is correct. 381654729 is not the only number though. Execute the following program and it will list all such elements

import java.util.*;
public class Selection {

 private ArrayList<Integer> WorkingSet = new ArrayList<Integer>(); 
 private ArrayList<Integer> TempSet = new ArrayList<Integer>();
 
 public static void main(String[] args)
 {
	Selection sel = new Selection();
	sel.getTheNum();
 }
 
 public void getTheNum()
 {
	this.WorkingSet.add(1);
	this.WorkingSet.add(2);
	this.WorkingSet.add(3);
	this.WorkingSet.add(4);
	this.WorkingSet.add(5);
	this.WorkingSet.add(6);
	this.WorkingSet.add(7);
	this.WorkingSet.add(8);
	this.WorkingSet.add(9);
	
	try 
	{
		for (int i = 2; i <= 9; i++)
		{
			Iterator<Integer> iter = this.WorkingSet.iterator();
			System.out.println("Elements after iteration no-" + i + " " + WorkingSet.toString());
			Thread.sleep(2000);
			while(iter.hasNext())
			{
				Integer num = iter.next();
				num *= 10; 
				for (int j = 1; j <= 9; j++)
				{				
					num += j;
					if ((num % i) == 0)
						this.TempSet.add(num);
					num -= j;
				}
				
			}
			this.WorkingSet.clear();
			this.WorkingSet.addAll(TempSet);
			this.TempSet.clear();
		}
		System.out.println("Elements after last iteration no-" + WorkingSet.toString());
	}
	catch(InterruptedException ie)
	{
				
	}	
 }
 
}

- Dumbo September 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<cstdlib>
#include<cmath>

using namespace std;

bool checknum(char s[],int  n)
{ 
     if(s[0]=='0')
       return false;
     s[n]='\0';
     int num=atoi(s);
     
    // cout<<"num ="<<num<<"\n";
    //getchar();
    bool b[10]={0};
    
     for(int i=n;i>1;i--)
     {
            if(num%i!=0)
              {  //cout<<num<<"not div by "<<i<<"\n";
                        return false;
              }
              
              int r=num%10;
               num=num/10;
               if(b[r]==1)
               return false;
               else
                 b[r]=1;
               
     }
     
     return true;
}

void  findnum(char s[],int n)
{
      if(n==9)
      { s[n] ='\0';
              cout<<s<<"****\n";
             
              return;
      }
      else
      {
         
          for(int i= 0 ; i<10 ; i++ )
          {      
          
                  s[n]='0'+i;
                  if(checknum(s,n+1))
                    findnum(s,n+1); 
                  //else
                   // findnum(s,n);     
          }
      }
}

int main()
{
    
    
   char s[10]={"100000000"};
    findnum(s,0);
    return 0;
}

- Anonymous July 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is my code using backtracking which prints all 5 such numbers..using

- Anonymous July 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

simple recursion if we know for n-1 digit we can get for n digits

public HashMap<Integer,HashSet<Integer>> findPolyDivisibleNumber(int n)
	{
		
		HashMap<Integer,HashSet<Integer>> map=new HashMap<Integer,HashSet<Integer>>();
		HashSet<Integer> sets;
		if(n==1)
		{
			for(int i=1;i<=9;i++)
			{
				sets=new HashSet<Integer>();
				sets.add(i);
				map.put(i, sets);
			}
			return map;
		}
		HashMap<Integer,HashSet<Integer>> oldMap=findPolyDivisibleNumber(n-1);
		Set<Integer> old=oldMap.keySet();
		Iterator<Integer> itr=old.iterator();
		
		while(itr.hasNext())
		{
			int temp=itr.next();
			HashSet<Integer> set=oldMap.get(temp);
			HashSet<Integer> setRes;
			for(int i=1;i<=9;i++)
			{
				if((temp*10+i)%n==0 && !set.contains(i))
				{
					setRes=new HashSet<Integer>();
					setRes.add(i);
					setRes.addAll(set);
					map.put(temp*10+i,setRes);
				}
			}
		}
		return map;
	}

- Anonymous December 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static void FindNumbers(String result, String numberStr) {
int len = numberStr.length();
if (result.length() >= 9) {
System.out.println(result);
}
else {
for (int i = 0; i < numberStr.length(); i++) {

int nlen = result.length();
if (Integer.parseInt(result + numberStr.charAt(i)) % (nlen + 1) == 0)
FindNumbers(result + numberStr.charAt(i), numberStr.substring(0, i) + numberStr.substring(i + 1, len));
}
}
}

- John January 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

call: FindNumbers ("", "213456789");

- Anonymous January 01, 2014 | 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