## Find the Only Repetitive Element Between 1 to N-1

In finding the only repetitive element between 1 to N-1 problem we have given an array of random integers within a range from 1 to n-1. There will be one number that is repeated. Your task is to find that number. Example Input [2,3,4,5,2,1] Output 2 Explanation 2 is the …

## Trapping Rain Water

In Trapping Rain Water problem we have given N non-negative integers representing an elevation map and the width of each bar is 1. We have to find the amount of water that can be trapped in the above structure. Example Let’s understand that by an example For the above elevation …

## Finding K closest element

In Finding K closest element problem we have given a sorted array and a value x. The problem is to find the K number of elements closest to x in the given array. Given an array arr[] ={12, 16, 22, 30, 35, 39, 42,45, 48, 50, 53, 55, 56} and x …

## Jump Game

In jump game we have given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index. Example Input: arr = [2,3,1,1,4] …

## Combination Sum

In combination sum problem we have given an array of positive integers arr[] and a sum s, find all unique combinations of elements in arr[] where the sum of those elements is equal to s. The same repeated number may be chosen from arr[] an unlimited number of times. Elements …

## Search in Sorted Rotated Array

An element search in sorted rotated array can be found using binary search in O(logn) time. The objective of this post is to find a given element in a sorted rotated array in O(logn) time. Some example of a sorted rotated array is given. Example Input : arr[] = {7,8,9,10,1,2,3,5,6}; …

## Maximum Subarray

In the Maximum Subarray problem we have given an integer array nums, find the contiguous sub array which has the largest sum and print the maximum sum subarray value. Example Input nums[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4} Output 6 Algorithm The goal is to find …

## Sliding Window Maximum

In Sliding Window Maximum problem we have given an array nums, for each contiguous window of size k, find the maximum element in the window. Example Input nums[] = {1,3,-1,-3,5,3,6,7} k = 3 Output {3,3,5,5,6,7} Explanation Naive Approach for Sliding Window Maximum For every contiguous window of size k, traverse …

## Delete And Earn

In delete and earn problem we have given an array nums, you may perform the following operation on the array elements. In one operation you can choose any array element(say nums[i]) and get points equal to that element and delete all the occurrences of (nums[i] – 1) and (nums[i] + …

## Length of Longest Fibonacci Subsequence

Given a strictly increasing array of positive integers, find the length of the longest fibonacci subsequence. A sequence of n elements is fibonacci like if, n >= 3 xi = x(i – 2) + x(i -1), where xi is the ith term of the sequence and i >= 2 Examples Input arr[] …