Big Fish Interview Question for iOS Developers

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
of 2 vote

I chose to map from the key to a list of ordered values (for collisions):

import java.util.*;

public class HelloWorld{

    public static void main(String []args){
        Map<String,List<String>> parsed = parse("TestName_KV1_KV2_LV1_LV2.txt");
        parsed = parse(null);
        parsed = parse("");
        parsed = parse("TestName");
        parsed = parse("TestName_");
        parsed = parse("TestName__");
        parsed = parse("TestName_K_");
        parsed = parse("johndoe_sdfjkldfj_ldfjlkfdsjfds_dfdjklfdsjs.txt");
    static Map<String,List<String>> parse(String fileName) {
        Map<String,List<String>> kToPositionedVs = new HashMap<String,List<String>>();
        if (fileName != null) {
            fileName = fileName.split("[.]")[0];
            String[] toks = fileName.split("_");
            List<String> singleValueForName = new ArrayList<String>();
            kToPositionedVs.put("Name", singleValueForName);
            if (toks.length > 1) {
                for (int i = 1; i < toks.length; i++) {
                    String curTok = toks[i];
                    String k = null;
                    String v = null;
                    if (curTok.length() == 1) {
                        k = curTok;
                        v = "";
                    } else if (curTok.length() > 1) {
                        k = curTok.substring(0, 1);
                        v = curTok.substring(1, curTok.length());
                    if (k != null) {
                        List<String> positionedVs = kToPositionedVs.get(k);
                        if (positionedVs == null) {
                            positionedVs = new ArrayList<String>();
                            kToPositionedVs.put(k, positionedVs);
        return kToPositionedVs;

Output is:

{Name=[TestName], L=[V1, V2], K=[V1, V2]}
{Name=[TestName], K=[]}
{Name=[johndoe], d=[fdjklfdsjs], s=[dfjkldfj], l=[dfjlkfdsjfds]}

This solution handles all of the corner cases I could think of:
1) Null fileName
2) Empty fileName
3) fileName with missing extension
4) fileName with no underscores
5) fileName with underscores, without key-value-pairs
6) fileName with underscores, with 1 or more key-emptyValue-pairs

What do you guys think? Any better way to parse this? Any corner cases I missed?

- caleb.cittadino April 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
of 1 vote

NSString *input = @"johndoe_sdfjkldfj_ldfjlkfdsjfds_dfdjklfdsjs.txt";
        input = [input substringToIndex:input.length-4];
		NSArray *components = [input componentsSeparatedByString:@"_"];
		NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithCapacity:components.count];
		if (components.count>0) {
			NSString *name = components[0];
			for (int i = 1; i<components.count; i++) {
                NSString *component = components[i];
				NSString *key = [component substringToIndex:1];
				NSString *value = [component substringFromIndex:1];
		NSLog(@"%@", result);

If duplicate token, I will not use the token as the key, I will use index as the key. Then make another mapping from index to token.

- read010931 May 06, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
of 1 vote

same as I was thinking. I would only change this line
input = [input substringToIndex:input.length-4];
with this
input = [input stringByDeletingPathExtension];

- crisredfi1 July 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
of 0 vote

Which company was this?

- peeterparker April 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

This is my shot with Objective-C. It's probably not the most elegant solution but it seems to work.

NSString *test = @"johndoe_sdfjkldfj_ldfjlkfdsjfds_dfdjklfdsjs.txt";

NSString *regexString = @"\\.(...)";

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexString options:NSRegularExpressionCaseInsensitive error:nil];

test = [regex stringByReplacingMatchesInString:test options:0 range:NSMakeRange(0, [test length]) withTemplate:@""];
NSMutableArray *testArray = [[NSMutableArray alloc]init];
[testArray addObjectsFromArray:[test componentsSeparatedByString:@"_"]];
 NSMutableDictionary *testDict = [[NSMutableDictionary alloc]init];
[testDict addEntriesFromDictionary:@{@"NAME":testArray[0]}];
[testArray removeObjectAtIndex:0];
for (NSString *string in testArray) {
        NSMutableString *mutString = [string mutableCopy];
        NSString *key = [mutString substringToIndex:1];
        [mutString deleteCharactersInRange:NSMakeRange(0, 1)];
        [testDict addEntriesFromDictionary:@{key:mutString}];
    NSLog(@"%@", testDict);

- Dare Ryan April 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

first create array of object and then add this array to dictionary....

- chavda pratik December 12, 2014 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More