Maximum contiguous subsequence sum problem Given an array of N integers. The array is expected to contain positive as well as negative numbers. Find the maximum contiguous subsequence sum (MCSS) of the array. For example the MCSS of {2, -4, 1, 2} is 3 which is the sum of the subsequence {1, 2}. A brute
Fibonacci numbers problem Write a program to compute the Fibonacci sequence number of a given integer. Your algorithm must run in linear time ie O(N). What is the fibonacci sequence Definition: Fibonacci number of (N) is the sum of Fibonacci numbers of (N-1) and (N-2). In other words, the fibonacci numbers list formula: where Fibonacci
String to integer in c++ Given an integer number in string format, for example “12345”. Write a program or function to convert a string to integer in C without using library. String to integer algorithm Loop through the characters of the string representing the integer number. Get the integer value of the current digit by
Database functional dependencies example Given the relation LDS (L, D, S) with the following functional dependencies definitions: LDS is decomposed into two relations: LD (L, D) and SL (S, L) which are populated as follows: Inserting the following row violates the functional dependency S, D -> L The question is how to enforce the the
Greatest common factor problem Given two integers A less than B. Write code to find the greatest common divisor between A and B commonly known as GCD. What is a greatest common factor GCD(A, B) is the largest positive integer that divides A and B without a remainder. We can loop starting at 2 ending
List of prime numbers Write a C++ program to find the prime numbers between 100 and 10000 What is a prime number Definition: A number (N) is prime if it has no divisors except 1 and (N) Prime number calculator To check if (N) is prime we divide (N) by all numbers from 3 to
Swapping two variables without a temp Given two integer variables A and B. Write C++ code to swap them without using a temporary variable. Solution This is a well known problem for which you can find so many references on the Internet. One way to do that is to use addition and subtraction as follows:
Problem Write a C++ algorithm that takes a string as input then check if the input string is Palindrome. A Palindrome string reads the same from left to right and from right to left as in the following example: Rats live on no evil star Solution We need one pass through the characters of the
Problem A typical interview question is to describe an algorithm to reverse a string of characters. Solution We need one pass through the characters of the string to get the string length or use a built in function to get that. Once the length of the string is found then one for loop can be
Problem If you run the following block of java code. How many times the print statement is going to execute. Solution You can modify the code by adding a counter then let the code itself calculates how many times it executes however that is not what the problem is all about. You can trace the