Problem Given the following sequence of integer numbers: Write a function that receives the index of a given number in the sequence above and returns the corresponding sequence number for example if index = 2 the function should return 2, if the index = 5 the function should return 8 and so on Solution The
Problem Given the path to a directory. Write a Perl script to print the average time to open and read all files in that directory. The files should be read in blocks of 64 KB Solution This is straightforward problem but we need to pay attention to the fact that files can grow in size
Problem Given a log file similar to Linux syslog format as in the following example: Write a Perl script to print the top 5 most repeated error messages. Solution Read the file line by line then split each line using “:” as separator then use the error message token as the key in a hash
Most repeated character string Given a string of characters find the character that is repeated the most. Solution This is almost the same as the First None Repeating Char problem. We are going to borrow the same code however we will slightly modify it. The only code that we need to add is calculating the
Problem Develop an algorithm to print the first none repeating character in a string for example the first none repeating character in the string “baby” is “a” Hash character in string This is a typical interview question. A better solution to solve this problem in linear time is to use a hash table on the
Problem Write code to simulate the SQL statement “Select unique emp_name from employees” Solution Assuming we have an array of employee names we need to write a function that prints the unique employee names in the array. We can use a built in hash table for that matter. Just hash all names then print the
Pairs with sum problem Given an array of integers A[N]. Find all pairs of integers in the array which sum to a given value (v) Solution Let us try to solve this problem using brute force approach Code for sum of pairs method Here is the code in Perl This is not an efficient solution
Find word count using perl Write a perl program that prints word count in file. For example if the input file contains the following word occurrences “Santa Clara is located in Santa Clara county” the program should print something like: Santa: 2 Clara: 2 is: 1 located: 1 in: 1 county: 1 Word count perl
Two arrays differences Given two integer arrays A and B of the same size each having no duplicate values. Write an equality function that returns true if A and B are equivalent. The arrays are equivalent if they contain the same content regardless of order. The function should return false if the arrays are not