Find two largest elements array Given an array of positive integers. Find the first and second largest elements in the array. Largest two numbers in an array solution One solution is to use two loops. The first loop finds the first maximum and the second loop finds the second maximum. Note that the second loop

Greedy algorithm interval scheduling problem An event starts at 9AM and finishes at 6PM. Several volunteers have signed to the event each providing a time period during which they can help. We need to cover the entire time of the event (9AM-6PM) with the least number of volunteers. Assume the next volunteer in line can

Optimized version of bubble sort Bubble sort is a slow comparison based sorting algorithm. Can you suggest one way to optimize it. Optimized bubble sort complexity and solution Bubble sort works by repeatedly visiting all elements of the list to be sorted comparing each pair of adjacent elements and swapping them if they are not

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

Integer division problem definition Given the following function which computes integer division. Debug the code and identify the major bugs. Modify the code to fix those bugs. Assume all integer variables are within range and no overflow is about to happen. int Division(int numerator, int denominator) { int quotient = 0; while (numerator > denominator)

Problem Write a function to compute the sum of integers between two given integer values. Solution The naive solution is to loop by going from the lower integer ending at the higher integer while calculating the sum. The other solution is compute the sum using the following formula Sum (1..n) = n (n + 1)/2

All Keyword in SQL Given the following database table: employee(emp_name, emp_salary) write an SQL statement to print the employee name with the highest salary Solution Using the max aggregate function will give us the maximum salary but it does not give us the name of the employee who has the maximum salary. The solution is

Problem You have the following database table: employee (emp_name, emp_age, emp_department) Write an SQL statement to calculate the average age of employees who are older than 30 years old for each department. Do not display the average if the number of employees used in the calculation is less than 3. Solution You need to use

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

Find non repeating character string 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" Algorithm A brute force method requires us to use two nested loops for character comparison. The moment we find a match we break the