| |
Booking.com Interview Questions
count the character and create a histogram
Booking.com Interview Questions
Booking.com Interview Questions Software Engineer ============================================== 1. Histogram ============================================== You have the file with a list of words at a single line. #input sample file abactor abaculus abacus Abadite . . Zyrenian #Output ******************************************************************a *************b **********************************c **********************d *******************************************************************************e a) you have to count the character and create a histogram in alphabetical order. b) now you have to produce a histogram with max 80 character in line in reference to max count c) now same out based histrogram based on the character count - madeinindia on March 24, 2014 in neitherland for perl backe ---------------------------------------------------------------------- Algorithm: Read file lines Initialise character_hash Accept only ENGLISH LATIN CHARATERS Buillt character_hash Find_Maximum_occurence (if bigger than 80 normlise maximum) Print hystogram http://eftpos-test.telekomcloud.hr/cgi-bin/mercur_histogram.cgi
=============================================== Multisets intersection =============================================== "A Multiset is a set where repetitions are allowed (ex: MS1 = (1,1,2,2,2,3,3,4,4,4,4,4,5,7,7,9...). Problem: write a program that receives two Multisets and returns intersections (element 2 appears three times on MS1 and five times on MS2 then intersection should contain the element three times." @ms1 = (1,1,2,2,2,3,3,4,4,4,4,4,5,7,7,9); @ms2 = (2,3,3,3); @intersection = (2,3,3,3); Algorithm: 1. built 2 hashes ms1 and ms2 2. loop through each key and print minimum =min(ms1{key},ms1{key}); ==============================================
============================================== 2. Picture compression ============================================== "Given an array of colors to represent an image (each element being a pixel color) ex.: (1,1,1,2,2,55,55,55,238,238,238,238,91,91,91,2,2,2,2,1,4,7,7,7,12,127) write a program that compress it." Part of a Software Developer Interview Review - one of 139 Booking.com Interview Reviews Result should contain pairs element,repetitions. Worst case would double the size of resulting array. Answer to example would be: (1,3,2,1,55,3,238,4,91,3,2,4,1,1,4,1,7,3,12,1,127,1)
============================================== 3. sort data structure by score =============================================== You have data structure my $users = [ { name => 'John', score => 10, }, { name => 'Bob', score => 1, }, { name => 'Carlos', score => 5 }, { name => 'Alice', score => 5, }, { name => 'Donald', score => 7 } ]; now u have to arrange the name with highest to lower score, if score is same than in alphabetical order #expected output: # John # Donald # Alice # Carlos # Bob"
my %hash = () ; foreach (@$users) { $hash{$_->{name}} = $_->{score}; } foreach (sort {$hash{$b} <=> $hash{$a}} keys %hash ) { print "$_\n"; } =============================================== "Symmetric Difference of Arrays" Input: two arrays of integers Output: one array of integers which occur in only one (not both) arrays Test case: Input A: [ 1, 7, 8, 2, 4, 5 ] Input B: [ 3, 5, 1, 7, 6, 9 ] Output: [ 8, 2, 4, 3, 6, 9 ] =============================================== write a regular expression for zip codes.
Second question was to write a program that takes two integer arrays and output the elements in two arrays and eliminate the duplicates. e.g [1, 2, 3, 4] and [3, 4, 5, 6] should output [1, 2, 3, 4, 5, 6]
Third question was to write down a bash script that mimics the find command that takes a root directory and file name and searched for that file name within this directory and enclosed subdirectory.
=============================================== Array intersection =============================================== "If you are given 2 array A={3,1,2,4} B={1,4}. Write a program to compare two arrays and create another array which holds the common values between two array!" #!/usr/bin/perl my @a = ('3','1','2','4','44'); my @b = ('23','44','1','4'); my @res; my %a_hash =(); foreach (@a) { ++$a_hash{$_}; }; foreach (@b) { if ($a_hash{$_} >0) {push @res; }; };
print "Common values @res\n"; ==========================================
|
|