valheru
BAN USER
- 0of 0 votes
AnswersGiven the following filename/rules:
- valheru in United States
johndoe_sdfjkldfj_ldfjlkfdsjfds_dfdjklfdsjs.txt
Rules:
johndoe is a distinct identifier (not a constant)
any following items are tacked on with underscores separating them and each token contains a key value pair. The key is the first character and the value is the remaining characters.
Parse this filename and return a dictionary/hashtable of values, removing any file extensions but also keeping in mind that this filename could end up with incorrect characters or incorrect amounts of characters.
Example input:
johndoe_sdfjkldfj_ldfjlkfdsjfds_dfdjklfdsjs.txt
Example output:
@{ @"NAME" : @"johndoe",
@"s" : @"dfjkldfj",
@"l" : @"dfjlkfdsjfds",
@"d": @"fdjklfdsjs"
};
Followup: How would you handle it if you found multiple tokens with the same key?| Report Duplicate | Flag | PURGE
Big Fish iOS Developer Algorithm - 2of 2 votes
AnswersGiven an array of words, write a method that determines whether there are any words in this array that are anagrams of each other.
- valheru in United States
Sample #1: @[@"bag", @"bat", @"tab"]; // output TRUE
Sample #2: @[@"gab", @"bat", @"laf"]; // output FALSE| Report Duplicate | Flag | PURGE
Facebook iOS Developer Algorithm - 0of 0 votes
AnswersAn UIView A2 is subclassed from the same parent as an UIView A1.
- valheru in United States
Given inputs of A1, A2, and an UIView that is in the tree of UIViews of A1 somewhere, return the exact UIView that mirrors this in A2.
Example setup:
A1------------
| |
UIView UIView
|
UIView <-- Given this
A2------------
| |
UIView UIView
|
UIView <-- Find/return this| Report Duplicate | Flag | PURGE
Facebook iOS Developer Trees and Graphs - 1of 1 vote
AnswersGiven a list of n sorted lists of numbers, write a method that returns one giant list of all the numbers in order.
- valheru in United States
Example input:
NSArray* input = @[
@[@2, @5, @10],
@[@25, @100, @105],
@[@7, @56, @42],
.......
];| Report Duplicate | Flag | PURGE
Facebook iOS Developer Sorting - 4of 4 votes
AnswersGiven the following hashmap for numeric to alpha translation of a telephone keypad:
- valheru in United States
NSDictionary* dict = @{@2: @[@"A", @"B", @"C"],
@3: @[@"D", @"E", @"F"],
@4: @[@"G", @"H", @"I"],
@5: @[@"J", @"K", @"L"],
@6: @[@"M", @"N", @"O"],
@7: @[@"P", @"Q", @"R", @"S"],
@8: @[@"T", @"U", @"V"],
@9: @[@"W", @"X", @"Y", @"Z"]};
Write a method that takes a phone number as input and returns all possible letter combinations for that phone number.| Report Duplicate | Flag | PURGE
Facebook iOS Developer Algorithm
Quick objective-c version with helper subroutine O(n)
For each word, swaps first and last till it gets to the middle.
- (NSString*)reverseString:(NSString*)input
{
NSMutableString* operateOn = [NSMutableString stringWithString:input];
NSUInteger firstIdx = 0;
NSUInteger lastIdx = input.length - 1;
while (firstIdx < lastIdx)
{
NSString* first = [NSString stringWithFormat:@"%c", [operateOn characterAtIndex:firstIdx]];
NSString* last = [NSString stringWithFormat:@"%c", [operateOn characterAtIndex:lastIdx]];
[operateOn replaceCharactersInRange:NSMakeRange(firstIdx, 1) withString:last];
[operateOn replaceCharactersInRange:NSMakeRange(lastIdx, 1) withString:first];
firstIdx++;
lastIdx--;
}
return [NSString stringWithString:operateOn];
}
- (NSString*)reverseWordsOfSentence:(NSString*)sentence
{
NSMutableString* newSent = [NSMutableString string];
NSArray* words = [sentence componentsSeparatedByString:@" "];
for (NSString* word in words)
{
[newSent appendFormat:@"%@ ", [self reverseString:word]];
}
// Remove extra space
[newSent deleteCharactersInRange:NSMakeRange(newSent.length - 1, 1)];
return [NSString stringWithString:newSent];
}
Without using specialized collections/data structures (of course).
- valheru April 24, 2014