Problem Given a square two dimensional integer array of size (n). Both rows and columns are sorted in ascending order. Give an algorithm to search for a particular element in the array in O(Log(n)) time complexity. Assume the array has no duplicates. Solution This problem is a follow up from the previous post. Modified binary
Problem Given a square two dimensional integer array of size (n). Both rows and columns are sorted in ascending order. Write an efficient code to search for a particular element in the array. Assume the array has no duplicates. Solution A brute force solution is to loop through the entire array until we find the
Given a sorted array of (n) integers that has been rotated an unknown number of times. Give a log(n) algorithm that finds an element in the array. Assume the array has no duplicates.
Array shuffle algorithm Given an array of 2n integers in the following format a1 a2 a3 … an b1 b2 b3 … bn. Rearrange the array as follows a1 b1 a2 b2 a3 b3 … an bn taking into consideration the following restrictions: 1. Arrange the array in place i.e. do not use any additional
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
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
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
Array recursive sum problem Given an array of N integers. Write a recursive function to calculate the sum of all elements in the array. Recursive sum algorithm The sum of N elements in a list is equivalent to the sum of one element of the array and the rest N-1 elements Code The following is
Recursive function to find max in array Write a recursive function to find the maximum value element in an Array of size N. Recursive definition of maximum In order to solve this problem recursively we need a stopping condition to break the chain of recursive calls. We also need to represent the solution for an array