Work in HR or Recruiting?
Epic
www.epic.com Verona, WI 5000+ Employees
Work in HR? Complete Your Profile

147 interview experiences Back to all Epic Interview Questions & Reviews

Interview Question for Software Developer at Epic:
Apr 19, 2012

Generate all well-ordered numbers given n digits.


Add Tags [?]

See more for this Epic Software Developer Interview

Helpful Question?  
Yes | No
Inappropriate?

Answers & Comments (1)

0 of 1 people found this helpful

May 7, 2012

by w1uo0:

import java.util.ArrayList;

public class Solution {
    public ArrayList<Integer[]> generateNumbers(int n) {
        ArrayList<Integer[]> ret = new ArrayList<Integer[]>();

        if (n > 10) {
            return ret;
        }

        Integer[] password = new Integer[n];

        solve(ret, password, n, 0);

        return ret;
    }

    public void solve(ArrayList<Integer[]> ret, Integer[] password, int n, int index) {
        if (index == n) {
            ret.add(password.clone());
        } else {
            for (int i = 0; i <= 9; i++) {
                if (isValid(password, index, i)) {
                    password[index] = i;
                    solve(ret, password, n, index + 1);
                }
            }
        }
    }

    public boolean isValid(Integer[] password, int index, int value) {
        if (index > 0 && password[index - 1] >= value) {
            return false;
        }

        return true;
    }
}
Helpful Answer?  
Yes | No
Inappropriate?

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.