# Tag: Array-programs

## Find subarray with given sumFind subarray with given sum

Find subarray with given sum Given an unsorted array of nonnegative integers, find a continuous subarray which adds to a given number. Examples : Input: arr[] = {1, 4, 20, 3, 10, 5}, sum = 33 Output: Sum found between

## Program to find largest element in an arrayProgram to find largest element in an array

Program to find largest element in an array Given an array, find the largest element in it. Example: Input : arr[] = {10, 20, 4} Output : 20 Input : arr[] = {20, 10, 20, 4, 100} Output : 100

## Find the Missing NumberFind the Missing Number

Find the Missing Number You are given a list of n-1 integers and these integers are in the range of 1 to n. There are no duplicates in the list. One of the integers is missing in the list. Write

## Maximum and minimum of an array using minimum number of comparisonsMaximum and minimum of an array using minimum number of comparisons

Maximum and minimum of an array using minimum number of comparisons   Write a C function to return minimum and maximum in an array. Your program should make the minimum number of comparisons. First of all, how do we return

## K’th Smallest/Largest Element in Unsorted ArrayK’th Smallest/Largest Element in Unsorted Array

K’th Smallest/Largest Element in Unsorted Array   Given an array and a number k where k is smaller than the size of the array, we need to find the k’th smallest element in the given array. It is given that

## Given an array A[] and a number x, check for pair in A[] with sum as xGiven an array A[] and a number x, check for pair in A[] with sum as x

Given an array A[] and a number x, check for pair in A[] with sum as x   Write a program that, given an array A[] of n numbers and another number x, determines whether or not there exist two

## Program for array rotationProgram for array rotation

Program for array rotation Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements. Rotation of the above array by 2 will make array METHOD 1 (Using temp array) Input arr[] = [1, 2, 3,

## Largest Sum Contiguous SubarrayLargest Sum Contiguous Subarray

Largest Sum Contiguous Subarray Write an efficient program to find the sum of contiguous subarray within a one-dimensional array of numbers that has the largest sum. Kadane’s Algorithm: Initialize: max_so_far = INT_MIN max_ending_here = 0 Loop for each element of

## Write a program to reverse an array or stringWrite a program to reverse an array or string

Program to reverse an array or string Given an array (or string), the task is to reverse the array/string. Examples : Input : arr[] = {1, 2, 3} Output : arr[] = {3, 2, 1} Input : arr[] = {4,