Capital One Interview Question: The most difficult question f... | Glassdoor

Interview Question

Software Engineer Interview Richmond, VA

The most difficult question for me was the coding

  questions. They asked about what a certain line of code did and then they had me code a sorting algorithm or sorts. I was asked to code a function that would find the first none repeated letter.
Answer

Interview Answer

2 Answers

0

could you iterate with a set and iterate again for the first instance of not containing the value in the set? O(n) + O(n) for an O(n) time and O(n) space?

stranger on Feb 14, 2015
0

sub first_non_repeating_letter {
    chomp $_[0];
    return "Null value inputed" if ($_[0] eq "");
    my @letters = split //, $_[0];
    my %character_count_of;

    foreach my $letter (@letters) {
        if ($character_count_of{$letter}) {
            $character_count_of{$letter}++;
        }
        else {
            $character_count_of{$letter} = 1;
        }
    }
    foreach my $letter (@letters) {
        next if ($character_count_of{$letter} != 1);
        next if $letter !~ /[a-zA-Z]/;
        return $letter;
    }
    return "All characters repeat";
}

stranger on Mar 3, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.