Booking.com Interview Question
Implement the MyStack. (A lot of questions about multi-threading)
@protocol Stack
-(void)pushObject:(nonnull id)obj;
-(nonnull id)popObjext;
@property(nonatomic,assign)NSInteger count;
@end
@interface MyStack : NSObject <Stack>
@end
@implementation MyStack
@end
Interview Answers
Did you have any system design questions?
Can you give me an example what you mean? Stack is considered as System Design?
@protocol Stack
-(void)pushObject:(nonnull id)obj;
-(nonnull id)popObject;
@property(nonatomic,assign) NSInteger count;
@end
@interface MyStack : NSObject
@property (nonatomic, strong) NSMutableArray *contents;
@end
@implementation MyStack
@synthesize count;
- (id)init {
if (self = [super init]) {
self.contents = [NSMutableArray array];
}
return self;
}
- (NSInteger)count
{
return self.contents.count;
}
- (void)pushObject:(nonnull id)obj
{
if(obj) {
[self.contents addObject:obj];
}
}
- (nonnull id)popObject
{
if ([self.contents count] > 0) {
id lastObj = [self.contents lastObject];
[self.contents removeLastObject];
return lastObj;
}
return [NSNumber numberWithInteger:-1];
}
- (void)print
{
for (id obj in self.contents) {
NSLog(@"%ld",(long)[(NSNumber*)obj integerValue]);
}
}
@end
You interviewed in person at booking? What kind of technical questions did you face? Could you give some details.