{"id":2404,"date":"2014-11-05T16:13:12","date_gmt":"2014-11-05T12:13:12","guid":{"rendered":"https:\/\/blog.alwawee.ru\/?p=2404"},"modified":"2014-11-06T07:46:00","modified_gmt":"2014-11-06T03:46:00","slug":"solution-ios-developer-technical-interview-problem","status":"publish","type":"post","link":"https:\/\/blog.alwawee.ru\/?p=2404","title":{"rendered":"Solution for iOS Developer Technical Interview Problem"},"content":{"rendered":"<p>I have <a href=\"http:\/\/horseshoe7.wordpress.com\/2012\/07\/25\/what-to-ask-an-ios-developer-at-their-interview\/\" title=\"http:\/\/horseshoe7.wordpress.com\/2012\/07\/25\/what-to-ask-an-ios-developer-at-their-interview\/\" target=\"_blank\">found an interesting iOS Developer Technical Interview Problem<\/a> and solved it.<\/p>\n<p>&#8220;I also have the ultimate iOS Developer technical test you can assign a potential hire.  It should take 1-3 hours.  It is easy to communicate, allows a lot of freedom of implementation so you can really get a better picture into how a developer thinks, and will make sure this developer knows the absolute fundamentals.  Ready for it?<\/p>\n<p><strong>Calculate the and display each Fibonacci number from 1 -> max N possible on an iPhone with unsigned integers, and display each F(n) in a table view.  The UITableView scrolling MUST remain smooth.<\/strong><\/p>\n<p>That\u2019s it.  You\u2019ll be amazed at how profoundly simple this task sounds and yet how much iOS knowledge can be demonstrated.  Not just what they know, but how they structure their work.  You can assess their APIs, their separation of concerns when designing classes, the considerations they\u2019ve made for performance, and their knowledge of concurrency.  (Not to mention their knowledge of recursive functions.)  It is ok to give them the formula, and allow them to use Google.  F(n) = F(n-1) + F(n-2).&#8221;<\/p>\n<p><strong>This is the result: <\/strong><br \/>\n<a href=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051-168x300.png\" alt=\"IMG_0051\" width=\"168\" height=\"300\" class=\"aligncenter size-medium wp-image-2405\" srcset=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051-168x300.png 168w, https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051-575x1024.png 575w, https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051.png 1125w\" sizes=\"auto, (max-width: 168px) 100vw, 168px\" \/><\/a><\/p>\n<p><strong>GitHub<\/strong> repository with a solution is <a href=\"https:\/\/github.com\/wzbozon\/fibo\" title=\"https:\/\/github.com\/wzbozon\/fibo\" target=\"_blank\">here<\/a>.<\/p>\n<p><strong>I used recursion and concurrency. I added a little delay of 0.1 s to make a delay visible but scrolling is still smooth. This is my solution: <\/strong><\/p>\n<pre>\r\n\/\/\r\n\/\/  FiboTableViewController.m\r\n\/\/  fibo\r\n\/\/\r\n\/\/  Created by Dennis Kutlubaev on 05.11.14.\r\n\/\/  Copyright (c) 2014 Alwawee. All rights reserved.\r\n\/\/\r\n\r\n#import \"FiboTableViewController.h\"\r\n\r\n\r\n@interface FiboTableViewController ()\r\n{\r\n    NSInteger _maxN;\r\n    dispatch_queue_t _backgroundQueue;\r\n}\r\n\r\n@property (nonatomic, strong) NSMutableArray *tableData;\r\n\r\n\r\n@end\r\n\r\n\r\n@implementation FiboTableViewController\r\n\r\n\r\n- (void)viewDidLoad\r\n{\r\n    [super viewDidLoad];\r\n    \r\n    NSLog(@\"Max Integer: %ld\", NSIntegerMax);\r\n    \r\n    _maxN = 10000;\r\n    \r\n    _backgroundQueue = dispatch_queue_create(\"background queue\", nil);\r\n    \r\n    [self loadData];\r\n}\r\n\r\n\r\n- (void)loadData\r\n{\r\n    _tableData = [NSMutableArray arrayWithArray:@[@(1),@(2)]];\r\n}\r\n\r\n\r\n#pragma mark - Table view data source\r\n\r\n- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView\r\n{\r\n    return 1;\r\n}\r\n\r\n- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section\r\n{\r\n    return _maxN;\r\n}\r\n\r\n\r\n- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath\r\n{\r\n    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];\r\n    \r\n    NSInteger n = indexPath.row;\r\n    __block NSInteger fibo;\r\n    if ( n < [_tableData count] ) {\r\n        fibo = [_tableData[n] integerValue];\r\n        if (fibo > 0) {\r\n            dispatch_async(dispatch_get_main_queue(), ^{\r\n                cell.textLabel.text = [NSString stringWithFormat:@\"%ld\", (long)fibo];\r\n            });\r\n        }\r\n    }\r\n    else {\r\n        dispatch_async(_backgroundQueue, ^{\r\n            \r\n            fibo = [self fibo:n];\r\n            dispatch_async(dispatch_get_main_queue(), ^{\r\n                if (fibo > 0) {\r\n                    cell.textLabel.text = [NSString stringWithFormat:@\"%ld\", (long)fibo];\r\n                }\r\n                else {\r\n                    [self.tableView reloadData];\r\n                    \/\/cell.textLabel.text = [NSString stringWithFormat:@\"Max integer reached: %ld\", NSIntegerMax];\r\n                }\r\n            });\r\n            \r\n        });\r\n    }\r\n    \r\n    return cell;\r\n}\r\n\r\n\r\n\/\/F(n) = F(n-1) + F(n-2)\r\n- (NSInteger)fibo:(NSInteger)n\r\n{\r\n    NSInteger f;\r\n    \r\n    if ( n < [_tableData count] ) {\r\n        f = [_tableData[n] integerValue];\r\n    }\r\n    else {\r\n        [NSThread sleepForTimeInterval:0.1];\r\n        \r\n        f = [self fibo:(n-2)] + [self fibo:(n-1)];\r\n        \r\n        if ((f < NSIntegerMax)&#038;&#038;(f > 0)) {\r\n            [_tableData addObject:@(f)];\r\n        }\r\n        else {\r\n            f = 0;\r\n            _maxN = n-1;\r\n        }\r\n    }\r\n    \r\n    return f;\r\n}\r\n\r\n\r\n@end\r\n\r\n<\/pre>\n<p>It scrolls without lags on <strong>iPhone 6 Plus<\/strong>. I do not calculate twice a fibonacci number if already have calculated it, I store a new fibonacci number in a <strong>NSMutableArray<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have found an interesting iOS Developer Technical Interview Problem and solved it. &#8220;I also have the ultimate iOS Developer technical test you can assign a potential hire. It should take 1-3 hours. It is easy to communicate, allows a lot of freedom of implementation so you can really get a better picture into how [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[149,187,150,151],"class_list":["post-2404","post","type-post","status-publish","format-standard","hentry","category-ios","tag-fibonacci","tag-ios","tag-technical-interview","tag-uitableview"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Solution for iOS Developer Technical Interview Problem - Denis Kutlubaev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alwawee.ru\/?p=2404\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Solution for iOS Developer Technical Interview Problem - Denis Kutlubaev\" \/>\n<meta property=\"og:description\" content=\"I have found an interesting iOS Developer Technical Interview Problem and solved it. &#8220;I also have the ultimate iOS Developer technical test you can assign a potential hire. It should take 1-3 hours. It is easy to communicate, allows a lot of freedom of implementation so you can really get a better picture into how [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alwawee.ru\/?p=2404\" \/>\n<meta property=\"og:site_name\" content=\"Denis Kutlubaev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/alwaweemobile\" \/>\n<meta property=\"article:published_time\" content=\"2014-11-05T12:13:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-11-06T03:46:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051-168x300.png\" \/>\n<meta name=\"author\" content=\"Denis Kutlubaev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Kutlubaev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404\"},\"author\":{\"name\":\"Denis Kutlubaev\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"headline\":\"Solution for iOS Developer Technical Interview Problem\",\"datePublished\":\"2014-11-05T12:13:12+00:00\",\"dateModified\":\"2014-11-06T03:46:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404\"},\"wordCount\":263,\"commentCount\":1,\"image\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/blog.alwawee.ru\\\/wp-content\\\/uploads\\\/2014\\\/11\\\/IMG_0051-168x300.png\",\"keywords\":[\"Fibonacci\",\"iOS\",\"Technical Interview\",\"UITableView\"],\"articleSection\":[\"iOS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404\",\"name\":\"Solution for iOS Developer Technical Interview Problem - Denis Kutlubaev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/blog.alwawee.ru\\\/wp-content\\\/uploads\\\/2014\\\/11\\\/IMG_0051-168x300.png\",\"datePublished\":\"2014-11-05T12:13:12+00:00\",\"dateModified\":\"2014-11-06T03:46:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404#primaryimage\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/wp-content\\\/uploads\\\/2014\\\/11\\\/IMG_0051.png\",\"contentUrl\":\"https:\\\/\\\/blog.alwawee.ru\\\/wp-content\\\/uploads\\\/2014\\\/11\\\/IMG_0051.png\",\"width\":1125,\"height\":2001},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2404#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.alwawee.ru\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Solution for iOS Developer Technical Interview Problem\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/\",\"name\":\"Denis Kutlubaev\",\"description\":\"iOS Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.alwawee.ru\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\",\"name\":\"Denis Kutlubaev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"caption\":\"Denis Kutlubaev\"},\"description\":\"iOS Developer, creator of Tornado Browser and many other popular apps\",\"sameAs\":[\"http:\\\/\\\/dennis.alwawee.com\"],\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Solution for iOS Developer Technical Interview Problem - Denis Kutlubaev","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.alwawee.ru\/?p=2404","og_locale":"en_US","og_type":"article","og_title":"Solution for iOS Developer Technical Interview Problem - Denis Kutlubaev","og_description":"I have found an interesting iOS Developer Technical Interview Problem and solved it. &#8220;I also have the ultimate iOS Developer technical test you can assign a potential hire. It should take 1-3 hours. It is easy to communicate, allows a lot of freedom of implementation so you can really get a better picture into how [&hellip;]","og_url":"https:\/\/blog.alwawee.ru\/?p=2404","og_site_name":"Denis Kutlubaev","article_publisher":"https:\/\/www.facebook.com\/alwaweemobile","article_published_time":"2014-11-05T12:13:12+00:00","article_modified_time":"2014-11-06T03:46:00+00:00","og_image":[{"url":"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051-168x300.png","type":"","width":"","height":""}],"author":"Denis Kutlubaev","twitter_misc":{"Written by":"Denis Kutlubaev","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.alwawee.ru\/?p=2404#article","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/?p=2404"},"author":{"name":"Denis Kutlubaev","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"headline":"Solution for iOS Developer Technical Interview Problem","datePublished":"2014-11-05T12:13:12+00:00","dateModified":"2014-11-06T03:46:00+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=2404"},"wordCount":263,"commentCount":1,"image":{"@id":"https:\/\/blog.alwawee.ru\/?p=2404#primaryimage"},"thumbnailUrl":"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051-168x300.png","keywords":["Fibonacci","iOS","Technical Interview","UITableView"],"articleSection":["iOS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.alwawee.ru\/?p=2404#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.alwawee.ru\/?p=2404","url":"https:\/\/blog.alwawee.ru\/?p=2404","name":"Solution for iOS Developer Technical Interview Problem - Denis Kutlubaev","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=2404#primaryimage"},"image":{"@id":"https:\/\/blog.alwawee.ru\/?p=2404#primaryimage"},"thumbnailUrl":"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051-168x300.png","datePublished":"2014-11-05T12:13:12+00:00","dateModified":"2014-11-06T03:46:00+00:00","author":{"@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"breadcrumb":{"@id":"https:\/\/blog.alwawee.ru\/?p=2404#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.alwawee.ru\/?p=2404"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blog.alwawee.ru\/?p=2404#primaryimage","url":"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051.png","contentUrl":"https:\/\/blog.alwawee.ru\/wp-content\/uploads\/2014\/11\/IMG_0051.png","width":1125,"height":2001},{"@type":"BreadcrumbList","@id":"https:\/\/blog.alwawee.ru\/?p=2404#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.alwawee.ru\/"},{"@type":"ListItem","position":2,"name":"Solution for iOS Developer Technical Interview Problem"}]},{"@type":"WebSite","@id":"https:\/\/blog.alwawee.ru\/#website","url":"https:\/\/blog.alwawee.ru\/","name":"Denis Kutlubaev","description":"iOS Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.alwawee.ru\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7","name":"Denis Kutlubaev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","caption":"Denis Kutlubaev"},"description":"iOS Developer, creator of Tornado Browser and many other popular apps","sameAs":["http:\/\/dennis.alwawee.com"],"url":"https:\/\/blog.alwawee.ru\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2404"}],"version-history":[{"count":0,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2404\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}