Headspring Interview Question: Questions are fairly easy, if... | Glassdoor.co.in

Interview Question

Senior .NET Developer Interview Sam Houston, TX (US)

Questions are fairly easy, if you really know things, here

  are completed set of all questions I get: 1) Create a program to display numbers between 1-100, but if the number is divisible by 3, print 'fizz' if divisible by 5, print 'buzz'. If divisible by both 3 &5 print 'fizz buzz' 2) Create reusable library (DLL) for the code above and write code to use that library 3) Instead of printing hardcode numbers 1-100, and fizz/buzz, allow user to specify those parameters whichever way they like 4) Modify the code to return some sort of indication if they specify invalid range such as 100-1 instead of 1-100 5) write unit test for this program (I didn't answer this one, cuz I have never use it) 6) Modify the code so that it can handle any condition for example what if user specified range from 1billion to 10billions. (not quite sure what interviewer wanted me to do on this at all) --Most difficult part? not really I was having fun, the interviewer made me feel like he was very happy with my code, but it was a total fake, he I turned around a gave me a negative assessment LOL for couple not really that important questions #5-6, may be because I was interviewed for a 6-digit salary and not a junior or mid level so he expected a whole lot more??? That is alright I wasn't looking for job at the time, HeadSpring VP contacted me first via LinkedIn and I thought why not give it a try, if I get it....great! otherwise, life goes on! so hope this helps to whoever next!
Answer

Interview Answer

3 Answers

0

//My answer for question 1:
namespace ConsoleApplication1{
class Program {
static void Main(string[] args) {
    int x=1, y = 100;
    string fizz = "Fizz", buzz = "Buzz";
    StringBuilder sb = new StringBuilder();

    for (int i = x; i y) throw new Exception("invalid range"); //for question 4
            Process(x);
        }

        public void Process(int i) {
            try {
                if (i% 3 == 0 && i % 5 == 0)
                    sb.Append(string.Format("\n{0} {1} {2}", i, fizz, buzz));
                else if (i % 3 == 0)
                    sb.Append(string.Format("\n{0} {1}", i, fizz));
                else if (i % 5 == 0)
                    sb.Append(string.Format("\n{0} {1}", i, buzz));
                else
                    sb.Append(string.Format("\n{0}", i));
                if (i == y) return;
                else Process(++i);
            }
            catch (Exception ex) { throw new Exception(ex.ToString()); }
        }

        public void Print() {
            Console.WriteLine(sb.ToString());
            Console.ReadLine();
        }
    }
}

//then modify main class Program as follow
namespace ConsoleApplication1{
class Program {
static void Main(string[] args) {
    int x=1, y = 100;
    string fizz = "Fizz", buzz = "Buzz";
 FizzBuzz objFB1 = new FizzBuzz(x, y, fizz, buzz);
 objFB1.Print();
}
}

--To GlassDoor, you can replace my previous post with this one as it is more readable -- thanks!

Interview Candidate on 04-Apr-2014
0

Can you please explain the 2nd question in detail . I have an interview this week. May I also know if you were asked to make any changes to this code. Thanks a lot.

Anonymous on 05-Mar-2015

One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.

Add Answers or Comments

To comment on this, Sign In or Sign Up.