Author: Andrey
-
Google phone interview for iOS mobile developer position
An outline of google phone interview: Question 1 // Create a function that takes int numbers[1000] and sorts it into ascending order (lowest to highest) I asked an interviewer if bubble sort is ok, or does he wants something more complex. He said that bubble sort is good enough. I also talked about the complexity,…
-
Flatten a recursive Linked List in Objective-C
Given a linked list, where each node’s value can itself be a linked list (a recursive linked list), write a function that flattens it. Final code at Github Pretty difficult coding questions. First I tried a recursive solution that for some reason wasn’t working for all cases and then I came up with this one.…
-
Sherlock and Array – Question from hackerrank
Just finish a fun question from Hackerrank: Sherlock and Array Question description: Watson gives Sherlock an array AA of length NN. Then he asks him to determine if there exists an element in the array such that the sum of the elements on its left is equal to the sum of the elements on its…
-
Coding question print binary tree by level in Objective C
This question was previously asked on the Facebook interview. Given input as a binary tree print to console each level followed by new line character. Input: Output: “A\n BC\n DEF” Solution: Do a breadth first search algorithm on a graph which will go over an entire tree and will build a resulted string. First of…
-
Recursively revert an array in Objective C
It’s a question that my fried received on a phone interview with one of the tech companies from West Coast Let’s do it! We will create a function reverseAnArray that takes a NSMutableArray and return void. +(void) reverseAnArray:(NSMutableArray *)input; 1. Set up a base – once we reach the end of the array we will…
-
Difference between formal and informal protocols
An informal protocol is a Category on NSObject. Implementation of the methods is optional. @interface NSObject(NSApplicationNotifications) – (void)applicationWillFinishLaunching:(NSNotification *)notification; … @interface NSObject(NSApplicationDelegate) – (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; … Formal protocols are an Extension to the Objective-C language. Methods can be required or optional. @protocol YourElementsViewDataSource – (NSUInteger)numberOfElements; – (CGFloat)sizeOfElementAtIndex:(NSUInteger)segmentIndex; @optional – (NSString *)titleForElementAtIndex:(NSUInteger)segmentIndex; – (BOOL)shouldExplodeElementAtIndex:(NSUInteger)segmentIndex; @required -…
-
Difference between shallow copy and deep copy
Shallow copy only copies a memory address. Changing one object will also change another. NSMutableArray *firstArray = [[NSMutableArray alloc] initWithObjects:@1, @2, @3, nil]; NSMutableArray *secondArray = [[NSMutableArray alloc] initWithObjects:@4, @5, @6, nil]; secondArray = firstArray; [secondArray setObject:@9 atIndexedSubscript:0]; NSLog(@”%@”, [firstArray objectAtIndex:0]); //9 the value in a first array has also changed Deep copy copies the…
-
Difference between frame and bound
Frame is a CGRect that is relative to it’s superview and bound is a CGRect that is relative to it’s own coordinate system. Practically (x,y) origin of bound would always be (0,0).
-
Hello World
As times goes by I do many coding work. I would like to publish some of it as it might be helpful for other developers. Let’s get started.