# Tag Archives: Pre-processing

## Maximum sum of elements in two non-overlapping contiguous sub arrays

Question: Given an array A, find the sum of maximum sum of two non-overlapping subarrays, with lengths L and M. In other words, return the largest V for which V = (A[i] + A[i+1] …. A[i+L-1]) + (A[j] + A[j+1] …. A[j+M-1]) Input: A = {3, 8, 1, 3, 2, 1, 8, 9, 0}; L = 3, M… Read More »

## Find the first N prime numbers. (Method 4) [Sieve of Eratosthenes]

Question: Given an integer N, find the prime numbers in that range from 1 to N. Input: N = 25 Output: 2, 3, 5, 7, 11, 13, 17, 19, 23 We have several ways of finding prime numbers. Some of the methods are discussed in the these posts. Method 1 Method 2 Method 3 In this post we… Read More »

## Find the sum of even Fibonacci numbers.

Question: Find the sum of even fibonacci numbers upto a limit N. Input:100 Output: 44 Fibonacci numbers are a miracle of Math and are defined as:- f(0) = 0 f(1) = 1 f(n) = f(n-1) + f(n-2); for n>=2 Thus the Fibonacci series can be given as 0, 1, 1, 2, 3, 5, 8, 13, 21… Let us… Read More »