Epic Systems Interview Question


Country: United States
Interview Type: Phone Interview




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

Java Code & Tested

public class Numbers {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Numbers numbers=new Numbers();
		
		numbers.printNumbers(3);

                //numbers.printNumbers(5);
	}
	
	
    public void printNumbers(int n){
    	int[] a={1,2,3,4,5,6,7,8,9};
    	
    	subPrint("",0,n,a);
    	
    }
    
    private void subPrint(String preFix,int startIndex,int numberCount,int[] a){
    	
    	for(int i=startIndex;i<a.length;i++){
    		
    		int digit=a[i];
    		
    		if(numberCount==1){
    			System.out.println(preFix+digit);
    		}else{
    			subPrint(preFix+digit,digit,numberCount-1,a);
    		}
    		
    	}
    }
}

- xiaofan December 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

plz explain it

- codr December 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

This will work only if nos. given are sorted

- adsf March 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
3
of 5 vote

void printNumbers(int n, int op)
{
	int lastDigitUsed = (op/power(10,n))%10;
	for(int i=lastDigitUsed+1; i<10;i++)
	{
		int temp = op+i*(power(10, n-1));
		if(n == 1)
			printf("%d", temp);
		else 
			printNumbers(n-1, temp);
	}
			
}

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

can u please explain a bit what op is??

- codr December 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Op is the base number, this case should be 0.

printNumbers(3,0).

- xiaofan December 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Two votes for a code that doesn't compile??

- Felipe December 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Felipe, the human compiler: Feel free to register and downvote.

Who the hell tries to compile the code before voting? LOL.

- Anonymous December 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Anonymous: rs... to detect a for() syntax error doesn't require a compiler: "i<;". Just a bit of experience.

- Felipe December 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

static public void printNumbers(int n, int op)
{
int lastDigitUsed = (op/(int)(Math.pow(10,n)))%10;
for(int i=lastDigitUsed+1; i<=10-n;i++)
{
int temp = op+i*(int)(Math.pow(10, n-1));
if(n == 1)
System.out.print(temp+",");
else
printNumbers(n-1, temp);
}

}
public static void main (String[] args) throws java.lang.Exception
{
printNumbers(3,0);
}

- Java version November 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<stdio.h>
void printNumbers(int);
int power(int , int);
int main()
{
int n;
scanf("%d",&n);
printNumbers(n);
return 0;
}
void printNumbers(int n)
{
int i;
int in,fn;
in=power(10,n-1)+1;
fn=power(10,n)-1;
for(i=in;i<fn;i++)
{ int flag=1;
int j=i;
while(j>9)
{
int temp2 =j%10;
int temp1=(j/10)%10;
if(temp1<temp2)
{
j=j/10;
}
else
{
flag=0;
j=0;
}
}
if(flag==1)
{
printf("%d,",i);
}
}
}
int power(int num, int p)
{
int j;
int k=num;
for(j=1;j<p;j++)
{
num*=k;
}
return (num);
}

- AMIT GUPTA January 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

/*
Given n. Generate all numbers with number of digits equal to n, such that the digit to the right is greater than the left digit (ai+1 > ai). E.g. if n=3 (123,124,125,……129,234,…..789)
*/

#include <iostream>
#include <cmath>

static bool is_valid_number(int num, int digits) {
	int base = std::pow(10, digits - 1);
	int arr[digits];


	bool ret = true;
	int saved = -1;

	for(int i = 0; i < digits; ++i) {
		int res = num / base;
		//std::cout << "res: " << res << std::endl;
		num = num - (base * res);
		base /= 10;
		arr[i] = res;

		if(saved == -1) {
			saved = res;
			continue;
		}
		
		if(res <= saved) {
			ret = false;
			break;
		} else {
			saved = res;
			continue;
		}
	}

	return ret;
}

int main() {
	static const int digits = 3;
	
	int initial = std::pow(10, (digits - 1));
	int final = std::pow(10, digits); 
	
	while(initial < final) {
		if(is_valid_number(initial, digits))
			std::cout << initial << std::endl;

		++initial;
	}

	return 0; 
}

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

Solution in C++:

#include <cstdio>

int printNumber(char num[], int next, int remain)
{
    if(remain == 0){
        puts(num);
        return 1;
    }

    char smallest = next == 0 ? '1' : num[next-1]+1;
    char largest = '9' - remain + 1;
    int sum = 0;
    for(--remain; smallest <= largest; ++smallest){
        num[next] = smallest;
        sum += printNumber(num, next+1, remain);
    }
    return sum;
}
int printNumber(int n)
{
    if(n > 9) return 0;
    if(n == 9){
        puts("123456789");
        return 1;
    }
    char num[9];
    num[n] = '\0';
    return printNumber(num, 0, n);
}

int main()
{
    printf("%d in total\n", printNumber(4));

    return 0;
}

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

void printnum(int n, string s, int last){
if (n == 0) cout << s << " ";
for (int i = 1; i < last; i++){
printnum(n - 1, to_string(i) + s, i);
}
return;
}

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

#include<iostream>
using namespace std;
void printArr(int arr[],int size)
{
for(int i=0;i<size;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
}
void genUtil(int str[],int n,int pos,int prev)
{
if(9-prev<(n-pos-1))return;
if(pos==n)
{
printArr(str,n);
return;
}
for(int i=prev+1;i<=9;i++)
{
str[pos]=i;
genUtil(str,n,pos+1,i);
}
}
void generateNums(int n)
{
int str[n];
genUtil(str,n,0,0);
}
int main()
{
int n=4;
generateNums(n);
return 0;
}

- Sumit Khanna December 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Solution in C++

#include <iostream>
#include <math.h>
using namespace std;


void printSeq(int n, int sum, int lastDigit)
{
int res = 0;
if(n==0)
{
cout<<sum<<"\n";
}
else
{
for(int i = lastDigit+1; i <10; i++)
{
res = i * pow(10,n-1)+sum;
printSeq(n-1,res,i);
}

}
}


int main() {
// your code goes here
printSeq(3,0,0);
return 0;
}

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

import math
def function(n):
    count=0
    while(n>0):
        f=n%10
        g=(n%100)/10
        if(f>g):
            count=count+1
        n=n//10
    return (count)
a=int(input("Enter the no of digits: "))
for i in range(pow(10,a-1),pow(10,a)):
    if(function(i)==a):
       print(i)

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

import math
def function(n):
    count=0
    while(n>0):
        f=n%10
        g=(n%100)/10
        if(f>g):
            count=count+1
        n=n//10
    return (count)
a=int(input("Enter the no of digits: "))
for i in range(pow(10,a-1),pow(10,a)):
    if(function(i)==a):
       print(i)

- Tony Stark December 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static void getnum(String result, String number, int size){
if (size == 0)
System.out.println(result);
else {
for (int i = 0; i < number.length(); i++){
if (result.length() >= 1)
{
if (Integer.parseInt(result.charAt(result.length() - 1) + "") < Integer.parseInt(number.charAt(i)+""))
printnum(result + number.charAt(i), number, size - 1);
}
else
getnum(result + number.charAt(i), number, size - 1);
}
}
return;
}

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

call: getNumber ("", "123456789", 3);

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

static void getnum(String result, String number, int size){
if (size == 0)
System.out.println(result);
else {
for (int i = 0; i < number.length(); i++){
if (result.length() >= 1)
{
if (Integer.parseInt(result.charAt(result.length() - 1) + "") < Integer.parseInt(number.charAt(i)+""))
getnum(result + number.charAt(i), number, size - 1);
}
else
getnum(result + number.charAt(i), number, size - 1);
}
}
return;
}

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

n = 3;
st = 10^n - 1;
i = 1;
while st > 10^(n-1)
    myStr1 = sprintf('%.0f',st) - '0';
    myStr2 = [myStr1(2:1:n),0];
    if sum((myStr1(1:1:(n-1)) - myStr2(1:1:(n-1))) < 0) == n-1
        myArray(i) = st;
        i=i+1;
    end
    st=st-1;
end
myArray

- KH January 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Program
    {
        public void print_it(int init, int dig) {
            int num = init;
            while (init != 0) {

                if (init % 10 <= (init / 10) % 10) break;
                init = init / 10;
            }
            if (init == 0) Console.WriteLine(num);
        }
        public static void Main(string[] args)
        {
            Program a = new Program();
            int initial = (int)Math.Pow(10, 2);
            int final = (int)Math.Pow(10, 3);
            while (initial < final) {
                a.print_it(initial, 3);
                initial++;
            }
        }
    }

- sujay January 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Program
    {
        public void print_it(int init, int dig) {
            int num = init;
            while (init != 0) {

                if (init % 10 <= (init / 10) % 10) break;
                init = init / 10;
            }
            if (init == 0) Console.WriteLine(num);
        }
        public static void Main(string[] args)
        {
            Program a = new Program();
            int initial = (int)Math.Pow(10, 2);
            int final = (int)Math.Pow(10, 3);
            while (initial < final) {
                a.print_it(initial, 3);
                initial++;
            }
        }
    }

- sujay January 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static void rightGreaterleft(int n)
{
int low=(int) Math.pow(10, n-1);
int high=(int) (Math.pow(10, n)-1);
System.out.println(low+" "+high);
for(int i=low;i<=high;i++)
{
printNumbers(i,n);


}
}
static void printNumbers(int num,int digits)
{
String str=Integer.toString(num);
int i=0;
int flag=0;
while(i<digits-1)
{
if(str.charAt(i)>=str.charAt(i+1))
{
flag=1;
break;
}
i++;
}
if(flag==0)
System.out.println(str);
}

- Anonymous January 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static void rightGreaterleft(int n)
{
int low=(int) Math.pow(10, n-1);
int high=(int) (Math.pow(10, n)-1);
System.out.println(low+" "+high);
for(int i=low;i<=high;i++)
{
printNumbers(i,n);


}
}
static void printNumbers(int num,int digits)
{
String str=Integer.toString(num);
int i=0;
int flag=0;
while(i<digits-1)
{
if(str.charAt(i)>=str.charAt(i+1))
{
flag=1;
break;
}
i++;
}
if(flag==0)
System.out.println(str);
}

- Anonymous January 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
using namespace std;
void printArr(int arr[],int n)
{
	for(int i=0;i<n;i++)cout<<arr[i]<<" ";
	cout<<endl;
}
void genUtil(int arr[],int n,int pos)
{
	if(arr[pos-1]==9 && pos!=n)return;
	if(pos==n)printArr(arr,n);
	for(int i=arr[pos-1]+1;i<10;i++)
	{
		arr[pos]=i;
		genUtil(arr,n,pos+1);
	}
}
void generate(int n)
{
	if(n==0)return;
	int arr[n];
	for(int i=1;i<10;i++){
		arr[0]=i;
		genUtil(arr,n,1);
	}
}
int main() {
	generate(3);
	return 0;
}

- sumit khanna January 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void numbers(char [] sol, char current, int nivel, int fin){
		if(nivel > fin-1 ){
			System.out.println(sol);
		}
		else{
			for(char i=(char) (current+1); i<='9'; i++){
				sol[nivel]= i;
				numbers(sol, i, nivel+1, fin);
			}
		}
	}

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int fin = scan.nextInt();
		char [] sol = new char[fin];
		
		numbers(sol, '0', 0, fin);
	}

- jfsetien January 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<stdlib.h>
void print(int *a, int size)
{
int i;
for(i=1;i<size;i++)
printf("%d",a[i]);
printf("\n");
}
void allnumprint(int *a,int i,int size)
{
if(i>=size-1)
print(a,size);
else
{
a[i+1]=a[i]+1;
while(i<size-1&&a[i+1]<=9)
{
allnumprint(a,i+1,size);
a[i+1]+=1;
}
}
}
int main()
{
int i,n,*a;
printf("Enter number of digits:");
scanf("%d",&n);
n+=1;
a=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++)
a[i]=0;
allnumprint(a,0,n);

}

- anujyadav.nitk February 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int n = 4;
		double startNo = 0;
		int no = 1;
		for (int i = n - 1; i >= 0; i--) {
			startNo = no * (Math.pow(10, i)) + startNo;
			no++;
		}
		
		//System.out.println(startNo);
		int start = (int) startNo;
		//System.out.println(start);
		
		int base = 10;
		double maxNo = 0;
		int maxStart = 10 - n;
		int pow = n - 1;
		for (int i = maxStart ; i < 10; i++) {
			maxNo = i * (Math.pow(10, pow)) + maxNo;
			pow--;
		}
		System.out.println("maxNo " + maxNo);
		while (start <= maxNo) {
			int rem = start % base;
			int quo = start / base;
			for (int next = rem; next <10; next++) {
				System.out.println((quo*base) + next);
			}
			//base = base * 10;
			double nextStart = 0;
			for (int i = n - 1 ; i >= 0; i--) {
				nextStart = 1 * (Math.pow(10, i)) + nextStart;
			}
			//System.out.println(nextStart + "--------------");
			start = start + (int) nextStart;
			
		}

- Senthil Nathan Chockalingam February 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Answer would be F(number , 0,0).

F(digits_left, number,  min_dig) {
If(digits_left==0)print (number) ;
For(int i=min_dig+1;i<=10-digits_left;i++){
F(digits_left -1,number*10+i, i);
} 
}

- Vishwaraj anand March 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ProgressiveDigits {
	public static void main(String[] args){
		int n = 4;
		int digit = 0;
		int lower_bound = (int) Math.pow(10, n-1);
		int upper_bound = (int) Math.pow(10, n);
		for(int result = lower_bound; result < upper_bound; result++){
			if(checkProgress(n, result, digit)){
				System.out.println(result);
			}
		}		
	}
	
	static boolean checkProgress(int n, int result, int digit){			
		while(digit < n ){
			if((result/(int) Math.pow(10, digit))%10 > (result/(int) Math.pow(10, digit+1))%10){
				digit++;				
			}else{
				return false;
			}			
		}
		return true;
	}
	
}

- zyn468 April 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Following is my code in java:

public static void main(String args[])
	{
		calculate(0,3);
	}
	private static void calculate(int i,int len)
	{ int j;
		if(len==0)
		{
			System.out.println(i);
			i=i/10;
			return;
		}
		if(i%10==0)
		{for(j=1;j<=(9-len+1);j++)
		{
			i=j;
			calculate(i,len-1);
			i=i/10;
		}
		}
		else
		{
			for(j=((i%10)+1);j<10;j++)
			{
				i=i*10+j;
				calculate(i,len-1);
				i=i/10;
			}
		}
			
		
	}
}

- Ashish June 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.Scanner;

public class orderednos {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayList<Integer> al = new ArrayList<Integer>();
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		
		int start = (int) Math.pow(10, num-1);
		int end = (int) Math.pow(10, num);
		
		for(int i = start; i < end-1; i++)
		{
			
			if(i/Math.pow(10, num) > (i%10))
			{
				continue;
			}
			else
			{
				int temp=i;
				int count=0;
				for(int k=0; k <= num; k++ )
				{
					int remain = temp%10;
					al.add(remain);
					temp = temp/10;
				}
				int max = al.get(0);				
				for(int m=1; m < al.size();m++)
				{
					if(max > al.get(m))
					{
						max= al.get(m);
						count++;
					}
				}
				if(count == al.size()-1)
				{
					System.out.println(i);
				}
				al.clear();				
			}
		}
	}
}

- akshay10011@iiitd.ac.in August 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
using namespace std;
void fn(int num, int dig, int len)
{

    int i, no;
    if(len == 0)
    {
        cout<<num<<"\n";
        return;
    }
    for(i = dig; i<=9; i++)
    {
        no = (num*10)+i;
        fn(no, i+1, len-1);
    }
}
main()
{
    fn(0, 1, 3);
}

- siva October 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I use DFS to solve this problem. compiled!

public class Numbers {
	public static void main(String[] args){
		int[] num = {1, 2, 3, 4, 5, 6, 7, 8, 9};
		StringBuilder sb = new StringBuilder();
		helper(num, 0, sb, 3);
	}
	public static void helper(int[] num, int pos, StringBuilder sb, int size){
		if (sb.length() == size) {
			System.out.println(sb.toString());
		}
		for (int i = pos; i < num.length; i++) {
			sb.append(num[i]);
			helper(num, i + 1, sb, size);
			sb.deleteCharAt(sb.length() - 1);
		}
	}

}

- hengxingtianxia October 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void reur_call(int start, int end, int stage, int num)
{
	if(stage == 0)
	{
		cout << num << endl;
		return;
	}
	stage = stage -1;
	for(int i = start; i<= end; i++)
	{
		reur_call((i+1), (end+1), (stage), (num*10+i));
	}
}

void call()
{
	int input = 4;
	int start = 1;
	int end = 10 - input;
	reur_call(start, end, input, 0);
}

- eded4ever October 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{public class WellOrderedNumber
{
public void order(String str, int leng)
{
if(leng==0)
{
System.out.println(str);
}


char c;
if(str.length()==0)
{
c = '1';
}
else
{
c = (char)(str.charAt(str.length()-1)+1);
}
for(;c<'9';c++)
{
order(str+c,leng-1);
}

}

public static void main(String args[])
{
WellOrderedNumber w = new WellOrderedNumber();
w.order("", 3);
}
}

- raj November 11, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class mySolution {

	
	public static void perm(String num, int j){
		
		if(num.length() == 3){
			
			System.out.println(num);
			return;
		}
		
		for(int i = j; i<10; i++){
			
			perm(num + String.valueOf(i),i+1);
		}
	}
	
	public static void main(String[] args) {
		
	
		perm("",1);

	}

}

- Bharat November 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Basic recursive practice. Just don't forget 0 when n == 1.
Playable code:

ideone.com/OYUBa3

vector<int> helper(int n, int pre) {
	if (n == 0) return vector<int>{pre};

	vector<int> ret;
	for (int i = pre % 10 + 1; i <= 9; ++i) {
		auto tmp = helper(n - 1, pre * 10 + i);
		ret.insert(ret.end(), tmp.begin(), tmp.end());
	}
	return ret;
}

vector<int> gen(int n) {
	if (n <= 0) return vector<int>();
	auto ret = helper(n, 0);
	if (n == 1) ret.push_back(0);

	return ret;
}

- XiaoPiGu December 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

written in python 3

def q2(n):
    num = ""; unum = ""; ans = []
    for i in range(1, n + 1): num = num + str(i)
    for i in range(10-n, 10): unum = unum + str(i)
    num = int(num); unum = int(unum)
    
    for i in range(num - 1, unum + 1):
        d = list(map(int, str(i)))
        for j in range(len(d)-1):
            if d[j] < d[j + 1]:
                if j == n - 2: ans.append(i)
            else:
                break
    return ans

- Dustin Klo July 23, 2015 | 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