# Tag Archives: array-rearrange

## Shuffle array {a1, a2, .. an, b1, b2, .. bn} as {a1, b1, a2, b2, a3, b3, ……, an, bn} without using extra spaceOctober 16, 2017

Given an array of 2n elements in the following format { a1, a2, a3, a4, ….., an, b1, b2, b3, b4, …., bn }. The… Read More »

## Rearrange a binary string as alternate x and y occurrencesOctober 10, 2017

Given a binary string s and two integers x and y are given. Task is to arrange the given string in such a way so… Read More »

## Rearrange array such that even index elements are smaller and odd index elements are greaterOctober 8, 2017

Given an array, rearrange the array such that : If index i is even, arr[i] <= arr[i+1] If index i is odd, arr[i] >= arr[i+1]… Read More »

## Positive elements at even and negative at odd positionsSeptember 12, 2017

You have been given an array and you have to make a program to convert that array such that positive elements occur at even numbered… Read More »

## Move all negative numbers to beginning and positive to end with constant extra spaceSeptember 6, 2017

An array contains both positive and negative numbers in random order. Rearrange the array elements so that all negative numbers appear before all Examples: Input… Read More »

## Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest, ..August 26, 2017

Given an array of integers, task is to print the array in the order – smallest number, Largest number, 2nd smallest number, 2nd largest number,… Read More »

## Distinct adjacent elements in an arrayJuly 16, 2017

Given an array whether it is possible to obtain an array having distinct neighboring elements by swapping two neighboring array elements . Examples: Input :… Read More »

## Alternative SortingJune 29, 2017

Given an array of integers, print the array in such a way that the first element is first maximum and second element is first minimum… Read More »

## Maximize sum of consecutive differences in a circular arrayMarch 12, 2017

Given an array of n elements. Consider array as circular array i.e element after an is a1. The task is to find maximum sum of… Read More »

## Rearrange an array in maximum minimum form | Set 2 (O(1) extra space)March 7, 2017

Given a sorted array of positive integers, rearrange the array alternately i.e first element should be the maximum value, second minimum value, third-second max, fourth-second… Read More »

## Three way partitioning of an array around a given rangeFebruary 14, 2017

Given an array and a range [lowVal, highVal], partition the array around the range such that array is divided in three parts. 1) All elements… Read More »

## Move all negative elements to end in order with extra space allowedDecember 23, 2016

Given an unsorted array of both negative and positive integer. The task is place all negative element at the end of array without changing the… Read More »

## Sort an array according to absolute difference with given valueDecember 22, 2016

Given an array of n distinct elements and a number x, arrange array elements according to the absolute difference with x, i. e., element having… Read More »

## Rearrange positive and negative numbers with constant extra spaceJuly 19, 2016

Given an array of positive and negative numbers, arrange them such that all negative integers appear before all the positive integers in the array without… Read More »

## Sort an array in wave formDecember 27, 2014

Given an unsorted array of integers, sort the array into a wave like array. An array ‘arr[0..n-1]’ is sorted in wave form if arr[0] >=… Read More »