Websense Interview Question: Write a program on the whiteb... | Glassdoor

Interview Question

Associate Software Engineer Interview Austin, TX

Write a program on the whiteboard such that sum(n) returns

  the sum of all the numbers up to the nth number in the sequence {0, 1, 1, 2, 3, 5, 8, 13, ...} (I noticed that this was the Fibonacci sequence but he did not call it that). Given 9 balls designed to be identical, what is the best method to find the faulty ball in the least amount of steps given only a balance scale. That is, you have 9 balls and one of them is either heavier or lighter than the others. Write a simple calculator program that allows a user to give an input (example: 5*3+4/3-4*1) and the program computes the integer result accounting for order of operations (example: 5*3+4/3-4*1 = 15+0-4 = 11)
Answer

Interview Answer

1 Answer

0

working java code for sum function (with print out to better understand):

public static int sum(int[] n)
    {
        int x = 0;
        for(int i = 0; i < n.length - 1; i++)
        {
            System.out.println("x: " + x);
            x = x + n[i];
            System.out.println(" + " + "n[i]: " + n[i]);
        }
        return x;
    }

Anonymous on Jul 19, 2016

Add Answers or Comments

To comment on this, Sign In or Sign Up.