AppFolio

  www.appfolio.com
  www.appfolio.com

Interview Question

Software Engineer Intern Interview

1. Given an array that contains duplicates (except for one

  value), find the one value that does not have a duplicate in that array. Explain the complexity of your algorithm. So in the array: A = [2, 3, 4, 5, 2, 3, 4] your algorithm should return 5 since that's the value that does not have a duplicate. 2. Explain the process that happens when you type your username and hit submit on a website (HTTP, server/client communication, etc...)
Answer

Interview Answer

2 Answers

0

1. Use a HashMap (I didn't think to do this but looking back that seems like a fast way since it's O(1) to put and get()) You could just loop through the array and put/increment the value for each key in the map. Then loop through the array once more to get the values from the map and see which value is not == 2.

Interview Candidate on Jan 24, 2014
1

// You don't have to run through the hashmap again
public int notDuplicate(int[] array) {
        HashMap<Integer, Boolean> map = new HashMap<>();
        int current = array[0];
        for (int i : array) {
            if (map.get(i) == null) {
                 map.put(i, true);
                 current = i;
            } else if (map.get(i)) {
                  map.put(i, false);
            }
        }
        return current;
    }

Anonymous on Oct 6, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.