Fibonacci numbers

Recently while interviewing for new work, I keep getting asked the same interview question coding sample.

That is, write a function to do the Fibonacci number sequence. The last time I was asked to write a function to calculate the sequence.  This was a pleasant experience compared to writing it on a whiteboard.  So here it is, a view controller in Objective C that calculates the Fibonacci number sequence and pumps the output to NSLog().

[sourcecode language=”ObjC”]
//
// ViewController.h
// fib
//
// Created by chris warner on 2/5/14.
// Copyright (c) 2014 chris warner. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end
[/sourcecode]

 

[sourcecode language=”ObjC”]
//
// ViewController.m
// fib
//
// Created by chris warner on 2/5/14.
// Copyright (c) 2014 chris warner. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
-(NSNumber *) fibonacciWithInt:(unsigned int)iterator;
@end

@implementation ViewController

-(NSNumber *) fibonacciWithInt:(unsigned int)iterator
{
NSNumber *returnValue = [[NSNumber alloc] init];

}

  • (void)viewDidLoad
    {
    [super viewDidLoad];

    NSNumber *fibanocci = [self fibonacciWithInt:50];
    if (fibanocci != nil)
    NSLog(@"fibonacci value is:%@",[fibanocci stringValue]);
    // Do any additional setup after loading the view, typically from a nib.
    }

  • (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

@end
[/sourcecode]

I have been a software developer for a very long time now. Coding samples in interviews these days is an art of looking up the sample on the internet. So many people are asking this question that it is getting tiresome to answer over and over. In my past 3 interviews over the past year, I have been asked this question in each interview. As an interviewer you gain nothing from the experience because all a candidate needs to do is memorize the problem and recite the function on the whiteboard in an interview. Outside of their memorization skills, what have you learned about this potential candidate?

Do you know how well they can program, or how well they can memorize?

When I interview a potential candidate for a position, I rarely ask a coding question for just this reason.  If the person can intelligently and accurately answer technical questions that would imply an implicit knowledge of your companies primary coding language, then what is the point of the coding sample?