Maximum of two numbers without comparison Write a C++ function which takes two positive integers x and y as input then return x if x > y otherwise return y. Assume x is not equal to y. You are not allowed to use any comparison operator or any if statement. Solution: maximum of two numbers

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 force approach requires 3

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: Fibonacci(N) =

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

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