Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • GfG 160: Daily DSA
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • DSA
  • Interview Questions on Array
  • Practice Array
  • MCQs on Array
  • Tutorial on Array
  • Types of Arrays
  • Array Operations
  • Subarrays, Subsequences, Subsets
  • Reverse Array
  • Static Vs Arrays
  • Array Vs Linked List
  • Array | Range Queries
  • Advantages & Disadvantages
Open In App
Next Article:
Print left rotation of array in O(n) time and O(1) space
Next article icon

Reversal algorithm for Array rotation

Last Updated : 06 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report
Try it on GfG Practice
redirect icon
 

Given an array arr[] of size N, the task is to rotate the array by d position to the left.

Examples: 

Input:  arr[] = {1, 2, 3, 4, 5, 6, 7}, d = 2
Output: 3, 4, 5, 6, 7, 1, 2
Explanation: If the array is rotated by 1 position to the left, 
it becomes {2, 3, 4, 5, 6, 7, 1}.
When it is rotated further by 1 position,
it becomes: {3, 4, 5, 6, 7, 1, 2}

Input: arr[] = {1, 6, 7, 8}, d = 3
Output: 8, 1, 6, 7

 

Approach: We have already discussed several methods in this post. The ways discussed there are:

  • Using another temporary array.
  • Rotating one by one.
  • Using a juggling algorithm.

Another Approach (The Reversal Algorithm): Here we will be discussing another method which uses the concept of reversing a part of array. The intuition behind the idea is mentioned below:

Intuition:

If we observe closely, we can see that a group of array elements is changing its position. For example see the following array:
arr[] = {1, 2, 3, 4, 5, 6, 7} and d = 2. The rotated array is {3, 4, 5, 6, 7, 1, 2}

The group having the first two elements is moving to the end of the array. This is like reversing the array.

  • But the issue is that if we only reverse the array, it becomes {7, 6, 5, 4, 3, 2, 1}. 
  • After rotation the elements in the chunks having the first 5 elements {7, 6, 5, 4, 3} and the last 2 elements {2, 1} should be in the actual order as of the initial array [i.e., {3, 4, 5, 6, 7} and {1, 2}]but here it gets reversed. 
  • So if those blocks are reversed again we get the desired rotated array.

So the sequence of operations is:

  • Reverse the whole array 
  • Then reverse the last 'd' elements and 
  • Then reverse the first (N-d) elements.

As we are performing reverse operations it is also similar to the following sequence:

  • Reverse the first 'd' elements
  • Reverse last (N-d) elements
  • Reverse the whole array.

Algorithm: The algorithm can be described with the help of the below pseudocode:

Pseudocode:  

Algorithm reverse(arr, start, end):
    mid = (start + end)/2
    loop from i = start to mid:
        swap (arr[i], arr[end-(mid-i+1)])

Algorithm rotate(arr, d, N):
    reverse(arr, 1, d) ;
    reverse(arr, d + 1, N);
    reverse(arr, 1, N);

Illustration:

Follow the illustration below to for  better understanding of the algorithm and intuition:

For example take the array arr[] = {1, 2, 3, 4, 5, 6, 7} and d = 2.

Array
Array

The rotated array will look like:

Rotated Array
Rotated Array

1st Step: Consider the array as a combination of two blocks. One containing the first two elements and the other containing the remaining elements as shown above.

Considered 2 blocks
Considered 2 blocks

2nd Step: Now reverse the first d elements. It becomes as shown in the image

Reverse the first K elements
Reverse the first K elements

3rd Step: Now reverse the last (N-d) elements. It become as it is shown in the below image:

Reverse the last (N-K) elements
Reverse the last (N-K) elements

4th Step: Now the array is the exact reversed form of how it should be if left shifted d times. So reverse the whole array and you will get the required rotated array.

The total array is reversed
The total array is reversed

See that the array is now the same as the rotated array.

Below is the implementation of the above approach: 
 

C++
#include  // for reverse function
#include   // for input/output operations
#include     // for vector container
using namespace std;

// Function to rotate an array by k elements to the right
void rotateArray(vector<int>& arr, int k)
{
    // Find the size of the array
    int n = arr.size();

    // Mod k with the size of the array
    // To handle the case where k is greater than the size of the array
    k %= n;

    // Reverse the entire array
    reverse(arr.begin(), arr.end());

    // Reverse the first k elements
    reverse(arr.begin(), arr.begin() + k);

    // Reverse the remaining n-k elements
    reverse(arr.begin() + k, arr.end());
}

int main()
{
    // Initialize the array
    vector<int> arr = { 1, 2, 3, 4, 5 };

    // Number of elements to rotate to the right
    int k = 2;

    // Call the rotateArray function to rotate the array
    rotateArray(arr, k);

    // Print the rotated array
    for (int i : arr) {
        cout << i << " ";
    }

    // Return 0 to indicate successful termination of the program
    return 0;
}
C++
// C++ program for reversal algorithm
// of array rotation

#include 
using namespace std;

// Function to reverse arr[] 
// from index start to end
void reverseArray(int arr[], int start, int end)
{
    while (start < end) {
        int temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }
}

// Function to left rotate arr[] of size n by d
void leftRotate(int arr[], int d, int n)
{
    if (d == 0)
        return;
    
    // In case the rotating factor is
    // greater than array length
    d = d % n;

    reverseArray(arr, 0, d - 1);
    reverseArray(arr, d, n - 1);
    reverseArray(arr, 0, n - 1);
}

// Function to print an array
void printArray(int arr[], int size)
{
    for (int i = 0; i < size; i++)
        cout << arr[i] << " ";
}

// Driver code
int main()
{
    int arr[] = { 1, 2, 3, 4, 5, 6, 7 };
    int N = sizeof(arr) / sizeof(arr[0]);
    int d = 2;

    // Function call
    leftRotate(arr, d, N);
    printArray(arr, N);
    return 0;
}
C
// C/C++ program for reversal algorithm of array rotation
#include 

/*Utility function to print an array */
void printArray(int arr[], int size);

/* Utility function to reverse arr[] from start to end */
void reverseArray(int arr[], int start, int end);

/* Function to left rotate arr[] of size n by d */
void leftRotate(int arr[], int d, int n)
{

    if (d == 0)
        return;
    // in case the rotating factor is
    // greater than array length
    d = d % n;

    reverseArray(arr, 0, d - 1);
    reverseArray(arr, d, n - 1);
    reverseArray(arr, 0, n - 1);
}

/*UTILITY FUNCTIONS*/
/* function to print an array */
void printArray(int arr[], int size)
{
    int i;
    for (i = 0; i < size; i++)
        printf("%d ", arr[i]);
}

/*Function to reverse arr[] from index start to end*/
void reverseArray(int arr[], int start, int end)
{
    int temp;
    while (start < end) {
        temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }
}

/* Driver program to test above functions */
int main()
{
    int arr[] = { 1, 2, 3, 4, 5, 6, 7 };
    int n = sizeof(arr) / sizeof(arr[0]);
    int d = 2;

    leftRotate(arr, d, n);
    printArray(arr, n);
    return 0;
}
Java
// Java program for reversal algorithm of array rotation
import java.io.*;

class LeftRotate {
    /* Function to left rotate arr[] of size n by d */
    static void leftRotate(int arr[], int d)
    {

        if (d == 0)
            return;

        int n = arr.length;
        // in case the rotating factor is
        // greater than array length
        d = d % n;
        reverseArray(arr, 0, d - 1);
        reverseArray(arr, d, n - 1);
        reverseArray(arr, 0, n - 1);
    }

    /*Function to reverse arr[] from index start to end*/
    static void reverseArray(int arr[], int start, int end)
    {
        int temp;
        while (start < end) {
            temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }
    }

    /*UTILITY FUNCTIONS*/
    /* function to print an array */
    static void printArray(int arr[])
    {
        for (int i = 0; i < arr.length; i++)
            System.out.print(arr[i] + " ");
    }

    /* Driver program to test above functions */
    public static void main(String[] args)
    {
        int arr[] = { 1, 2, 3, 4, 5, 6, 7 };
        int n = arr.length;
        int d = 2;

        leftRotate(arr, d); // Rotate array by d
        printArray(arr);
    }
}
/*This code is contributed by Devesh Agrawal*/
Python3
# Python program for reversal algorithm of array rotation

# Function to reverse arr[] from index start to end


def reverseArray(arr, start, end):
    while (start < end):
        temp = arr[start]
        arr[start] = arr[end]
        arr[end] = temp
        start += 1
        end = end-1

# Function to left rotate arr[] of size n by d


def leftRotate(arr, d):

    if d == 0:
        return
    n = len(arr)
    # in case the rotating factor is
    # greater than array length
    d = d % n
    reverseArray(arr, 0, d-1)
    reverseArray(arr, d, n-1)
    reverseArray(arr, 0, n-1)

# Function to print an array


def printArray(arr):
    for i in range(0, len(arr)):
        print (arr[i],end=' ')


# Driver function to test above functions
arr = [1, 2, 3, 4, 5, 6, 7]
n = len(arr)
d = 2

leftRotate(arr, d)  # Rotate array by 2
printArray(arr)

# This code is contributed by Devesh Agrawal
C#
// C# program for reversal algorithm
// of array rotation
using System;

class GFG {
    /* Function to left rotate arr[]
    of size n by d */
    static void leftRotate(int[] arr, int d)
    {

        if (d == 0)
            return;
        int n = arr.Length;
          // in case the rotating factor is
        // greater than array length
        d = d % n;
        reverseArray(arr, 0, d - 1);
        reverseArray(arr, d, n - 1);
        reverseArray(arr, 0, n - 1);
    }

    /* Function to reverse arr[] from
    index start to end*/
    static void reverseArray(int[] arr, int start,
                             int end)
    {
        int temp;
        while (start < end) {
            temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }
    }

    /*UTILITY FUNCTIONS*/
    /* function to print an array */
    static void printArray(int[] arr)
    {
        for (int i = 0; i < arr.Length; i++)
            Console.Write(arr[i] + " ");
    }

    // Driver code
    public static void Main()
    {
        int[] arr = { 1, 2, 3, 4, 5, 6, 7 };
        int n = arr.Length;
        int d = 2;

        leftRotate(arr, d); // Rotate array by 2
        printArray(arr);
    }
}

// This code is contributed by Sam007
PHP

// PHP program for reversal 
// algorithm of array rotation

/* Function to left rotate
   arr of size n by d */
function leftRotate(&$arr, $d, $n)
{

    if ($d == 0)
        return;
      // in case the rotating factor is
      // greater than array length
      $d = ($d % $n);
    reverseArray($arr, 0, $d - 1);
    reverseArray($arr, $d, $n - 1);
    reverseArray($arr, 0, $n - 1);
}

/*Function to reverse $arr
  from index start to end*/
function reverseArray(&$arr, 
                       $start, $end)
{
    while ($start < $end)
    {
        $temp = $arr[$start];
        $arr[$start] = $arr[$end];
        $arr[$end] = $temp;
        $start++;
        $end--;
    }
}

// Function to 
// print an array 
function printArray($arr, $size)
{
    for ($i = 0; $i < $size; $i++)
    print $arr[$i]." ";
}

// Driver code
$arr = array(1, 2, 3, 
             4, 5, 6, 7);
$n = sizeof($arr);
$d = 2;

// Function calling
leftRotate($arr, $d, $n);
printArray($arr, $n);
    
// This code is contributed
// by ChitraNayal
?>
JavaScript
<script>
      // JavaScript program for reversal algorithm
      // of array rotation

      /*Function to reverse arr[] from index start to end*/
      function reverseArray(arr, start, end) {
        while (start < end) {
          var temp = arr[start];
          arr[start] = arr[end];
          arr[end] = temp;
          start++;
          end--;
        }
      }

      /* Function to left rotate arr[] of size n by d */
      function leftRotate(arr, d, n) {
        if (d == 0) return;
        // in case the rotating factor is
        // greater than array length
        d = d % n;

        reverseArray(arr, 0, d - 1);
        reverseArray(arr, d, n - 1);
        reverseArray(arr, 0, n - 1);
      }

      // Function to print an array
      function printArray(arr, size) 
      {
        for (var i = 0; i < size; i++) document.write(arr[i] + " ");
      }

      /* Driver program to test above functions */

      var arr = [1, 2, 3, 4, 5, 6, 7];
      var n = arr.length;
      var d = 2;

      // Function calling
      leftRotate(arr, d, n);
      printArray(arr, n);
      
      // This code is contributed by rdtank.
    </script>

Output
3 4 5 6 7 1 2 

Time Complexity: O(N)
Auxiliary Space: O(1)

Another Method :-  Using C++ STL  reverse

C++
#include  // for reverse function
#include   // for input/output operations
#include     // for vector container
using namespace std;

// Function to rotate an array by k elements to the right
void rotateArray(vector<int>& arr, int k)
{
    // Find the size of the array
    int n = arr.size();

    // Mod k with the size of the array
    // To handle the case where k is greater than the size of the array
    k %= n;

    // Reverse the entire array
    reverse(arr.begin(), arr.end());

    // Reverse the first k elements
    reverse(arr.begin(), arr.begin() + k);

    // Reverse the remaining n-k elements
    reverse(arr.begin() + k, arr.end());
}

int main()
{
    // Initialize the array
    vector<int> arr = { 1, 2, 3, 4, 5 };

    // Number of elements to rotate to the right
    int k = 2;

    // Call the rotateArray function to rotate the array
    rotateArray(arr, k);

    // Print the rotated array
    for (int i : arr) {
        cout << i << " ";
    }

    // Return 0 to indicate successful termination of the program
    return 0;
}
Java
import java.util.ArrayList;
import java.util.Collections;

public class Main {
    public static void main(String[] args)
    {
        // Initialize the array
        ArrayList<Integer> arr = new ArrayList<>();
        arr.add(1);
        arr.add(2);
        arr.add(3);
        arr.add(4);
        arr.add(5);
        // Number of elements to rotate to the right
        int k = 2;

        // Call the rotateArray function to rotate the array
        rotateArray(arr, k);

        // Print the rotated array
        for (int i : arr) {
            System.out.print(i + " ");
        }
    }

    // Function to rotate an array by k elements to the
    // right
    public static void rotateArray(ArrayList<Integer> arr,
                                   int k)
    {
        // Find the size of the array
        int n = arr.size();

        // Mod k with the size of the array
        // To handle the case where k is greater than the
        // size of the array
        k %= n;

        // Reverse the entire array
        Collections.reverse(arr);

        // Reverse the first k elements
        for (int i = 0; i < k / 2; i++) {
            int temp = arr.get(i);
            arr.set(i, arr.get(k - i - 1));
            arr.set(k - i - 1, temp);
        }

        // Reverse the remaining n-k elements
        for (int i = k; i < (n + k) / 2; i++) {
            int temp = arr.get(i);
            arr.set(i, arr.get(n + k - i - 1));
            arr.set(n + k - i - 1, temp);
        }
    }
}
Python3
# Function to rotate an array by k elements to the right
def rotateArray(arr, k):
    # Find the size of the array
    n = len(arr);

    # Mod k with the size of the array
    # To handle the case where k is greater than the size of the array
    k %= n;

    # Reverse the entire array
    arr[0:n] = arr[0:n][::-1]

    # Reverse the first k elements
    arr[0:k] = arr[0:k][::-1]

    # Reverse the remaining n-k elements
    arr[k:n] = arr[k:n][::-1]

# Initialize the array
arr = [ 1, 2, 3, 4, 5 ];

# Number of elements to rotate to the right
k = 2;

# Call the rotateArray function to rotate the array
rotateArray(arr, k);

# Print the rotated array
for i in range(0,len(arr)):
    print(arr[i], end= " ");
JavaScript
// Define the function to rotate an array
function rotateArray(arr, k) {
// Find the length of the array
const n = arr.length;

// Mod k with the length of the array
// To handle the case where k is greater than the
// length of the array
k %= n;

// Reverse the entire array
arr.reverse();

// Reverse the first k elements
for (let i = 0; i < k / 2; i++) {
const temp = arr[i];
arr[i] = arr[k - i - 1];
arr[k - i - 1] = temp;
}

// Reverse the remaining n-k elements
for (let i = k; i < (n + k) / 2; i++) {
const temp = arr[i];
arr[i] = arr[n + k - i - 1];
arr[n + k - i - 1] = temp;
}
}

// Initialize the array
const arr = [1, 2, 3, 4, 5];

// Number of elements to rotate to the right
const k = 2;

// Call the rotateArray function to rotate the array
rotateArray(arr, k);

// Print the rotated array
console.log(arr.join(' '));
C#
using System;
using System.Linq;

namespace ArrayRotation {
class Program {
    static void Main(string[] args)
    {
        // Initialize the array
        int[] arr = { 1, 2, 3, 4, 5 };

        // Number of elements to rotate to the right
        int k = 2;

        // Call the RotateArray function to rotate the array
        RotateArray(ref arr, k);

        // Print the rotated array
        Console.WriteLine(string.Join(" ", arr));

        // Wait for the user to end the program
        Console.ReadKey();
    }

    // Function to rotate an array by k elements to the
    // right
    static void RotateArray(ref int[] arr, int k)
    {
        // Find the size of the array
        int n = arr.Length;

        // Mod k with the size of the array
        // To handle the case where k is greater than the
        // size of the array
        k %= n;

        // Reverse the first n-k elements
        Array.Reverse(arr, 0, n - k);

        // Reverse the remaining k elements
        Array.Reverse(arr, n - k, k);

        // Reverse the entire array
        Array.Reverse(arr);
    }
}
}

Output
4 5 1 2 3 

Time Complexity: O(N)
Auxiliary Space: O(1)


Next Article
Print left rotation of array in O(n) time and O(1) space
author
kartik
Improve
Article Tags :
  • DSA
  • Arrays
  • Codenation
  • rotation
Practice Tags :
  • Codenation
  • Arrays

Similar Reads

    Array Data Structure
    Complete Guide to ArraysLearn more about Array in DSA Self Paced CoursePractice Problems on ArraysTop Quizzes on Arrays What is Array?An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calcul
    3 min read
    What is Array?
    Array is a linear data structure where all elements are arranged sequentially. It is a collection of elements of same data type stored at contiguous memory locations. For simplicity, we can think of an array as a flight of stairs where on each step is placed a value (let's say one of your friends).
    2 min read
    Getting Started with Array Data Structure
    Array is a collection of items of the same variable type that are stored at contiguous memory locations. It is one of the most popular and simple data structures used in programming. Basic terminologies of ArrayArray Index: In an array, elements are identified by their indexes. Array index starts fr
    14 min read
    Applications, Advantages and Disadvantages of Array
    Array is a linear data structure that is a collection of data elements of same types. Arrays are stored in contiguous memory locations. It is a static data structure with a fixed size.Table of ContentApplications of Array Data Structure:Advantages of Array Data Structure:Disadvantages of Array Data
    2 min read
    Subarrays, Subsequences, and Subsets in Array
    What is a Subarray?A subarray is a contiguous part of array, i.e., Subarray is an array that is inside another array. In general, for an array of size n, there are n*(n+1)/2 non-empty subarrays. For example, Consider the array [1, 2, 3, 4], There are 10 non-empty sub-arrays. The subarrays are: (1),
    10 min read

    Basic operations in Array

    Searching in Array
    Searching is one of the most common operations performed in an array. Array searching can be defined as the operation of finding a particular element or a group of elements in the array. There are several searching algorithms. The most commonly used among them are: Linear Search Binary Search Ternar
    4 min read
    Array Reverse - Complete Tutorial
    Given an array arr[], the task is to reverse the array. Reversing an array means rearranging the elements such that the first element becomes the last, the second element becomes second last and so on.Examples: Input: arr[] = {1, 4, 3, 2, 6, 5} Output: {5, 6, 2, 3, 4, 1}Explanation: The first elemen
    15+ min read
    Rotate an Array by d - Counterclockwise or Left
    Given an array of integers arr[] of size n, the task is to rotate the array elements to the left by d positions.Examples:Input: arr[] = {1, 2, 3, 4, 5, 6}, d = 2Output: {3, 4, 5, 6, 1, 2}Explanation: After first left rotation, arr[] becomes {2, 3, 4, 5, 6, 1} and after the second rotation, arr[] bec
    15+ min read
    Print array after it is right rotated K times
    Given an Array of size N and a value K, around which we need to right rotate the array. How do you quickly print the right rotated array?Examples : Input: Array[] = {1, 3, 5, 7, 9}, K = 2.Output: 7 9 1 3 5Explanation:After 1st rotation - {9, 1, 3, 5, 7}After 2nd rotation - {7, 9, 1, 3, 5} Input: Arr
    15+ min read
    Search, Insert, and Delete in an Unsorted Array | Array Operations
    In this post, a program to search, insert, and delete operations in an unsorted array is discussed.Search Operation:In an unsorted array, the search operation can be performed by linear traversal from the first element to the last element. Coding implementation of the search operation:C++// C++ prog
    15+ min read
    Search, Insert, and Delete in an Sorted Array | Array Operations
    How to Search in a Sorted Array?In a sorted array, the search operation can be performed by using binary search.Below is the implementation of the above approach:C++// C++ program to implement binary search in sorted array #include using namespace std; int binarySearch(int arr[
    15+ min read
    Array Sorting - Practice Problems
    Sorting an array means arranging the elements of the array in a certain order. Generally sorting in an array is done to arrange the elements in increasing or decreasing order. Problem statement: Given an array of integers arr, the task is to sort the array in ascending order and return it, without u
    9 min read
    Generating All Subarrays
    Given an array arr[], the task is to generate all the possible subarrays of the given array.Examples: Input: arr[] = [1, 2, 3]Output: [ [1], [1, 2], [2], [1, 2, 3], [2, 3], [3] ]Input: arr[] = [1, 2]Output: [ [1], [1, 2], [2] ]Iterative ApproachTo generate a subarray, we need a starting index from t
    8 min read

    Easy problems on Array

    Largest three distinct elements in an array
    Given an array arr[], the task is to find the top three largest distinct integers present in the array.Note: If there are less than three distinct elements in the array, then return the available distinct numbers in descending order.Examples :Input: arr[] = [10, 4, 3, 50, 23, 90]Output: [90, 50, 23]
    6 min read
    Second Largest Element in an Array
    Given an array of positive integers arr[] of size n, the task is to find second largest distinct element in the array.Note: If the second largest element does not exist, return -1. Examples:Input: arr[] = [12, 35, 1, 10, 34, 1]Output: 34Explanation: The largest element of the array is 35 and the sec
    14 min read
    Move all zeros to end of array
    Given an array of integers arr[], the task is to move all the zeros to the end of the array while maintaining the relative order of all non-zero elements.Examples: Input: arr[] = [1, 2, 0, 4, 3, 0, 5, 0]Output: arr[] = [1, 2, 4, 3, 5, 0, 0, 0]Explanation: There are three 0s that are moved to the end
    15 min read
    Rearrange array such that even positioned are greater than odd
    Given an array arr[], sort the array according to the following relations: arr[i] >= arr[i - 1], if i is even, ∀ 1 <= i < narr[i] <= arr[i - 1], if i is odd, ∀ 1 <= i < nFind the resultant array.[consider 1-based indexing]Examples: Input: arr[] = [1, 2, 2, 1]Output: [1 2 1 2] Expla
    9 min read
    Rearrange an array in maximum minimum form using Two Pointer Technique
    Given a sorted array of positive integers, rearrange the array alternately i.e first element should be a maximum value, at second position minimum value, at third position second max, at fourth position second min, and so on. Examples: Input: arr[] = {1, 2, 3, 4, 5, 6, 7} Output: arr[] = {7, 1, 6, 2
    6 min read
    Segregate even and odd numbers using Lomuto’s Partition Scheme
    Given an array arr[] of integers, segregate even and odd numbers in the array such that all the even numbers should be present first, and then the odd numbers.Examples: Input: arr[] = {7, 2, 9, 4, 6, 1, 3, 8, 5}Output: 2 4 6 8 7 9 1 3 5Input: arr[] = {1, 3, 2, 4, 7, 6, 9, 10}Output: 2 4 6 10 7 1 9 3
    6 min read
    Reversal algorithm for Array rotation
    Given an array arr[] of size N, the task is to rotate the array by d position to the left. Examples: Input: arr[] = {1, 2, 3, 4, 5, 6, 7}, d = 2Output: 3, 4, 5, 6, 7, 1, 2Explanation: If the array is rotated by 1 position to the left, it becomes {2, 3, 4, 5, 6, 7, 1}.When it is rotated further by 1
    15 min read
    Print left rotation of array in O(n) time and O(1) space
    Given an array of size n and multiple values around which we need to left rotate the array. How to quickly print multiple left rotations?Examples : Input : arr[] = {1, 3, 5, 7, 9}k1 = 1k2 = 3k3 = 4k4 = 6Output : 3 5 7 9 17 9 1 3 59 1 3 5 73 5 7 9 1Input : arr[] = {1, 3, 5, 7, 9}k1 = 14 Output : 9 1
    15+ min read
    Sort an array which contain 1 to n values
    We are given an array that contains 1 to n elements, our task is to sort this array in an efficient way. We are not allowed to simply copy the numbers from 1 to n.Examples : Input : arr[] = {2, 1, 3};Output : {1, 2, 3}Input : arr[] = {2, 1, 4, 3};Output : {1, 2, 3, 4} Native approach - O(n Log n) Ti
    7 min read
    Count Possible Triangles
    Given an unsorted array of positive integers, the task is to find the number of triangles that can be formed with three different array elements as three sides of triangles. For a triangle to be possible from 3 values as sides, the sum of the two values (or sides) must always be greater than the thi
    15+ min read
    Print all Distinct (Unique) Elements in given Array
    Given an integer array arr[], print all distinct elements from this array. The given array may contain duplicates and the output should contain every element only once.Examples: Input: arr[] = {12, 10, 9, 45, 2, 10, 10, 45}Output: {12, 10, 9, 45, 2}Input: arr[] = {1, 2, 3, 4, 5}Output: {1, 2, 3, 4,
    11 min read
    Unique Number I
    Given an array of integers, every element in the array appears twice except for one element which appears only once. The task is to identify and return the element that occurs only once.Examples: Input: arr[] = [2, 3, 5, 4, 5, 3, 4]Output: 2 Explanation: Since 2 occurs once, while other numbers occu
    8 min read
    Leaders in an array
    Given an array arr[] of size n, the task is to find all the Leaders in the array. An element is a Leader if it is greater than or equal to all the elements to its right side. Note: The rightmost element is always a leader. Examples: Input: arr[] = [16, 17, 4, 3, 5, 2]Output: [17 5 2]Explanation: 17
    10 min read
    Subarray with Given Sum
    Given a 1-based indexing array arr[] of non-negative integers and an integer sum. You mainly need to return the left and right indexes(1-based indexing) of that subarray. In case of multiple subarrays, return the subarray indexes which come first on moving from left to right. If no such subarray exi
    10 min read

    Intermediate problems on Array

    Rearrange an array such that arr[i] = i
    Given an array of elements of length n, ranging from 0 to n - 1. All elements may not be present in the array. If the element is not present then there will be -1 present in the array. Rearrange the array such that arr[i] = i and if i is not present, display -1 at that place.Examples: Input: arr[] =
    13 min read
    Alternate Rearrangement of Positives and Negatives
    An array contains both positive and negative numbers in random order. Rearrange the array elements so that positive and negative numbers are placed alternatively. A number of positive and negative numbers need not be equal. If there are more positive numbers they appear at the end of the array. If t
    11 min read
    Reorder an array according to given indexes
    Given two integer arrays of the same length, arr[] and index[], the task is to reorder the elements in arr[] such that after reordering, each element from arr[i] moves to the position index[i]. The new arrangement reflects the values being placed at their target indices, as described by index[] arra
    15+ min read
    Find the smallest missing number
    Given a sorted array of n distinct integers where each integer is in the range from 0 to m-1 and m > n. Find the smallest number that is missing from the array. Examples: Input: {0, 1, 2, 6, 9}, n = 5, m = 10 Output: 3 Input: {4, 5, 10, 11}, n = 4, m = 12 Output: 0 Input: {0, 1, 2, 3}, n = 4, m =
    15 min read
    Difference Array | Range update query in O(1)
    You are given an integer array arr[] and a list of queries. Each query is represented as a list of integers where:[1, l, r, x]: Adds x to all elements from arr[l] to arr[r] (inclusive).[2]: Prints the current state of the array.You need to perform the queries in order.Examples : Input: arr[] = [10,
    10 min read
    Stock Buy and Sell – Max 2 Transactions Allowed
    In the stock market, a person buys a stock and sells it on some future date. Given the stock prices of n days in an array prices[ ]. Find out the maximum profit a person can make in at most 2 transactions. A transaction is equivalent to (buying + selling) of a stock and a new transaction can start o
    15+ min read
    Smallest subarray with sum greater than a given value
    Given an array arr[] of integers and a number x, the task is to find the smallest subarray with a sum strictly greater than x.Examples:Input: x = 51, arr[] = [1, 4, 45, 6, 0, 19]Output: 3Explanation: Minimum length subarray is [4, 45, 6]Input: x = 100, arr[] = [1, 10, 5, 2, 7]Output: 0Explanation: N
    15+ min read
    Count Inversions of an Array
    Given an integer array arr[] of size n, find the inversion count in the array. Two array elements arr[i] and arr[j] form an inversion if arr[i] > arr[j] and i < j.Note: Inversion Count for an array indicates that how far (or close) the array is from being sorted. If the array is already sorted
    15+ min read
    Merge Two Sorted Arrays Without Extra Space
    Given two sorted arrays a[] and b[] of size n and m respectively, the task is to merge both the arrays and rearrange the elements such that the smallest n elements are in a[] and the remaining m elements are in b[]. All elements in a[] and b[] should be in sorted order.Examples: Input: a[] = [2, 4,
    15+ min read
    Majority Element
    You are given an array arr, and your task is to find the majority element an element that occurs more than half the length of the array (i.e., arr.size() / 2). If such an element exists return it, otherwise return -1, indicating that no majority element is present.Examples : Input : arr[] = [1, 1, 2
    15+ min read
    Two Pointers Technique
    Two pointers is really an easy and effective technique that is typically used for Two Sum in Sorted Arrays, Closest Two Sum, Three Sum, Four Sum, Trapping Rain Water and many other popular interview questions. Given a sorted array arr (sorted in ascending order) and a target, find if there exists an
    11 min read
    3 Sum - Triplet Sum in Array
    Given an array arr[] of size n and an integer sum, the task is to check if there is a triplet in the array which sums up to the given target sum.Examples: Input: arr[] = [1, 4, 45, 6, 10, 8], target = 13Output: true Explanation: The triplet [1, 4, 8] sums up to 13Input: arr[] = [1, 2, 4, 3, 6, 7], t
    15 min read
    Equilibrium Index
    Given an array arr[] of size n, the task is to return an equilibrium index (if any) or -1 if no equilibrium index exists. The equilibrium index of an array is an index such that the sum of all elements at lower indexes equals the sum of all elements at higher indexes. Note: When the index is at the
    15 min read

    Hard problems on Array

    MO's Algorithm (Query Square Root Decomposition) | Set 1 (Introduction)
    Let us consider the following problem to understand MO's Algorithm. We are given an array and a set of query ranges, we are required to find the sum of every query range.Example: Input: arr[] = {1, 1, 2, 1, 3, 4, 5, 2, 8}; query[] = [0, 4], [1, 3] [2, 4]Output: Sum of arr[] elements in range [0, 4]
    15+ min read
    Square Root (Sqrt) Decomposition Algorithm
    Square Root Decomposition Technique is one of the most common query optimization techniques used by competitive programmers. This technique helps us to reduce Time Complexity by a factor of sqrt(N) The key concept of this technique is to decompose a given array into small chunks specifically of size
    15+ min read
    Sparse Table
    Sparse table concept is used for fast queries on a set of static data (elements do not change). It does preprocessing so that the queries can be answered efficiently.Range Minimum Query Using Sparse TableYou are given an integer array arr of length n and an integer q denoting the number of queries.
    15+ min read
    Range sum query using Sparse Table
    We have an array arr[]. We need to find the sum of all the elements in the range L and R where 0 <= L <= R <= n-1. Consider a situation when there are many range queries. Examples: Input : 3 7 2 5 8 9 query(0, 5) query(3, 5) query(2, 4) Output : 34 22 15Note : array is 0 based indexed and q
    8 min read
    Range LCM Queries
    Given an array arr[] of integers of size N and an array of Q queries, query[], where each query is of type [L, R] denoting the range from index L to index R, the task is to find the LCM of all the numbers of the range for all the queries.Examples: Input: arr[] = {5, 7, 5, 2, 10, 12 ,11, 17, 14, 1, 4
    15+ min read
    Jump Game - Minimum Jumps to Reach End
    Given an array arr[] of non-negative numbers. Each number tells you the maximum number of steps you can jump forward from that position.For example:If arr[i] = 3, you can jump to index i + 1, i + 2, or i + 3 from position i.If arr[i] = 0, you cannot jump forward from that position.Your task is to fi
    15+ min read
    Space optimization using bit manipulations
    There are many situations where we use integer values as index in array to see presence or absence, we can use bit manipulations to optimize space in such problems.Let us consider below problem as an example.Given two numbers say a and b, mark the multiples of 2 and 5 between a and b using less than
    12 min read
    Maximum value of Sum(i*arr[i]) with array rotations allowed
    Given an array arr[], the task is to determine the maximum possible value of the expression i*arr[i] after rotating the array any number of times (including zero).Note: In each rotation, every element of the array shifts one position to the right, and the last element moves to the front.Examples : I
    12 min read
    Construct an array from its pair-sum array
    Given a pair-sum array construct the original array. A pair-sum array for an array is the array that contains sum of all pairs in ordered form, i.e., pair[0] is sum of arr[0] and arr[1], pair[1] is sum of arr[0] and arr[2] and so on. Note that if the size of input array is n, then the size of pair a
    5 min read
    Maximum equilibrium sum in an array
    Given an array arr[]. Find the maximum value of prefix sum which is also suffix sum for index i in arr[].Examples : Input : arr[] = {-1, 2, 3, 0, 3, 2, -1}Output : 4Explanation : Prefix sum of arr[0..3] = Suffix sum of arr[3..6]Input : arr[] = {-3, 5, 3, 1, 2, 6, -4, 2}Output : 7Explanation : Prefix
    11 min read
    Smallest Difference Triplet from Three arrays
    Three arrays of same size are given. Find a triplet such that maximum - minimum in that triplet is minimum of all the triplets. A triplet should be selected in a way such that it should have one number from each of the three given arrays. If there are 2 or more smallest difference triplets, then the
    9 min read
    Top 50 Array Coding Problems for Interviews
    Array is one of the most widely used data structure and is frequently asked in coding interviews to the problem solving skills. The following list of 50 array coding problems covers a range of difficulty levels, from easy to hard, to help candidates prepare for interviews.Easy ProblemsSecond Largest
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

'); // $('.spinner-loading-overlay').show(); let script = document.createElement('script'); script.src = 'https://assets.geeksforgeeks.org/v2/editor-prod/static/js/bundle.min.js'; script.defer = true document.head.appendChild(script); script.onload = function() { suggestionModalEditor() //to add editor in suggestion modal if(loginData && loginData.premiumConsent){ personalNoteEditor() //to load editor in personal note } } script.onerror = function() { if($('.editorError').length){ $('.editorError').remove(); } var messageDiv = $('
').text('Editor not loaded due to some issues'); $('#suggestion-section-textarea').append(messageDiv); $('.suggest-bottom-btn').hide(); $('.suggestion-section').hide(); editorLoaded = false; } }); //suggestion modal editor function suggestionModalEditor(){ // editor params const params = { data: undefined, plugins: ["BOLD", "ITALIC", "UNDERLINE", "PREBLOCK"], } // loading editor try { suggestEditorInstance = new GFGEditorWrapper("suggestion-section-textarea", params, { appNode: true }) suggestEditorInstance._createEditor("") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } //personal note editor function personalNoteEditor(){ // editor params const params = { data: undefined, plugins: ["UNDO", "REDO", "BOLD", "ITALIC", "NUMBERED_LIST", "BULLET_LIST", "TEXTALIGNMENTDROPDOWN"], placeholderText: "Description to be......", } // loading editor try { let notesEditorInstance = new GFGEditorWrapper("pn-editor", params, { appNode: true }) notesEditorInstance._createEditor(loginData&&loginData.user_personal_note?loginData.user_personal_note:"") $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = true; } catch (error) { $('.spinner-loading-overlay:eq(0)').remove(); editorLoaded = false; } } var lockedCasesHtml = `You can suggest the changes for now and it will be under 'My Suggestions' Tab on Write.

You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!`; var badgesRequiredHtml = `It seems that you do not meet the eligibility criteria to create improvements for this article, as only users who have earned specific badges are permitted to do so.

However, you can still create improvements through the Pick for Improvement section.`; jQuery('.improve-header-sec-child').on('click', function(){ jQuery('.improve-modal--overlay').hide(); $('.improve-modal--suggestion').hide(); jQuery('#suggestion-modal-alert').hide(); }); $('.suggest-change_wrapper, .locked-status--impove-modal .improve-bottom-btn').on('click',function(){ // when suggest changes option is clicked $('.ContentEditable__root').text(""); $('.suggest-bottom-btn').html("Suggest changes"); $('.thank-you-message').css("display","none"); $('.improve-modal--improvement').hide(); $('.improve-modal--suggestion').show(); $('#suggestion-section-textarea').show(); jQuery('#suggestion-modal-alert').hide(); if(suggestEditorInstance !== null){ suggestEditorInstance.setEditorValue(""); } $('.suggestion-section').css('display', 'block'); jQuery('.suggest-bottom-btn').css("display","block"); }); $('.create-improvement_wrapper').on('click',function(){ // when create improvement option clicked then improvement reason will be shown if(loginData && loginData.isLoggedIn) { $('body').append('
'); $('.spinner-loading-overlay').show(); jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.unlocked-status--improve-modal-content').css("display","none"); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status) }, }); } else { if(loginData && !loginData.isLoggedIn) { $('.improve-modal--overlay').hide(); if ($('.header-main__wrapper').find('.header-main__signup.login-modal-btn').length) { $('.header-main__wrapper').find('.header-main__signup.login-modal-btn').click(); } return; } } }); $('.left-arrow-icon_wrapper').on('click',function(){ if($('.improve-modal--suggestion').is(":visible")) $('.improve-modal--suggestion').hide(); else{ } $('.improve-modal--improvement').show(); }); const showErrorMessage = (result,statusCode) => { if(!result) return; $('.spinner-loading-overlay:eq(0)').remove(); if(statusCode == 403) { $('.improve-modal--improve-content.error-message').html(result.message); jQuery('.improve-modal--overlay').show(); jQuery('.improve-modal--improvement').show(); $('.locked-status--impove-modal').css("display","block"); $('.unlocked-status--improve-modal-content').css("display","none"); $('.improve-modal--improvement').attr("status","locked"); return; } } function suggestionCall() { var editorValue = suggestEditorInstance.getValue(); var suggest_val = $(".ContentEditable__root").find("[data-lexical-text='true']").map(function() { return $(this).text().trim(); }).get().join(' '); suggest_val = suggest_val.replace(/\s+/g, ' ').trim(); var array_String= suggest_val.split(" ") //array of words var gCaptchaToken = $("#g-recaptcha-response-suggestion-form").val(); var error_msg = false; if(suggest_val != "" && array_String.length >=4){ if(editorValue.length <= 2000){ var payload = { "gfg_post_id" : `${post_id}`, "suggestion" : `${editorValue}`, } if(!loginData || !loginData.isLoggedIn) // User is not logged in payload["g-recaptcha-token"] = gCaptchaToken jQuery.ajax({ type:'post', url: "https://apiwrite.geeksforgeeks.org/suggestions/auth/create/", xhrFields: { withCredentials: true }, crossDomain: true, contentType:'application/json', data: JSON.stringify(payload), success:function(data) { if(!loginData || !loginData.isLoggedIn) { grecaptcha.reset(); } jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('.suggest-bottom-btn').css("display","none"); $('#suggestion-section-textarea').hide() $('.thank-you-message').css('display', 'flex'); $('.suggestion-section').css('display', 'none'); jQuery('#suggestion-modal-alert').hide(); }, error:function(data) { if(!loginData || !loginData.isLoggedIn) { grecaptcha.reset(); } jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Something went wrong."); jQuery('#suggestion-modal-alert').show(); error_msg = true; } }); } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Minimum 4 Words and Maximum Words limit is 1000."); jQuery('#suggestion-modal-alert').show(); jQuery('.ContentEditable__root').focus(); error_msg = true; } } else{ jQuery('.spinner-loading-overlay:eq(0)').remove(); jQuery('#suggestion-modal-alert').html("Enter atleast four words !"); jQuery('#suggestion-modal-alert').show(); jQuery('.ContentEditable__root').focus(); error_msg = true; } if(error_msg){ setTimeout(() => { jQuery('.ContentEditable__root').focus(); jQuery('#suggestion-modal-alert').hide(); }, 3000); } } document.querySelector('.suggest-bottom-btn').addEventListener('click', function(){ jQuery('body').append('
'); jQuery('.spinner-loading-overlay').show(); if(loginData && loginData.isLoggedIn) { suggestionCall(); return; } // script for grecaptcha loaded in loginmodal.html and call function to set the token setGoogleRecaptcha(); }); $('.improvement-bottom-btn.create-improvement-btn').click(function() { //create improvement button is clicked $('body').append('
'); $('.spinner-loading-overlay').show(); // send this option via create-improvement-post api jQuery.ajax({ url: writeApiUrl + 'create-improvement-post/?v=1', type: "POST", contentType: 'application/json; charset=utf-8', dataType: 'json', xhrFields: { withCredentials: true }, data: JSON.stringify({ gfg_id: post_id }), success:function(result) { $('.spinner-loading-overlay:eq(0)').remove(); $('.improve-modal--overlay').hide(); $('.create-improvement-redirection-to-write').attr('href',writeUrl + 'improve-post/' + `${result.id}` + '/', '_blank'); $('.create-improvement-redirection-to-write')[0].click(); }, error:function(e) { showErrorMessage(e.responseJSON,e.status); }, }); });
"For an ad-free experience and exclusive features, subscribe to our Premium Plan!"
Continue without supporting
`; $('body').append(adBlockerModal); $('body').addClass('body-for-ad-blocker'); const modal = document.getElementById("adBlockerModal"); modal.style.display = "block"; } function handleAdBlockerClick(type){ if(type == 'disabled'){ window.location.reload(); } else if(type == 'info'){ document.getElementById("ad-blocker-div").style.display = "none"; document.getElementById("ad-blocker-info-div").style.display = "flex"; handleAdBlockerIconClick(0); } } var lastSelected= null; //Mapping of name and video URL with the index. const adBlockerVideoMap = [ ['Ad Block Plus','https://media.geeksforgeeks.org/auth-dashboard-uploads/abp-blocker-min.mp4'], ['Ad Block','https://media.geeksforgeeks.org/auth-dashboard-uploads/Ad-block-min.mp4'], ['uBlock Origin','https://media.geeksforgeeks.org/auth-dashboard-uploads/ub-blocke-min.mp4'], ['uBlock','https://media.geeksforgeeks.org/auth-dashboard-uploads/U-blocker-min.mp4'], ] function handleAdBlockerIconClick(currSelected){ const videocontainer = document.getElementById('ad-blocker-info-div-gif'); const videosource = document.getElementById('ad-blocker-info-div-gif-src'); if(lastSelected != null){ document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.backgroundColor = "white"; document.getElementById("ad-blocker-info-div-icons-"+lastSelected).style.borderColor = "#D6D6D6"; } document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.backgroundColor = "#D9D9D9"; document.getElementById("ad-blocker-info-div-icons-"+currSelected).style.borderColor = "#848484"; document.getElementById('ad-blocker-info-div-name-span').innerHTML = adBlockerVideoMap[currSelected][0] videocontainer.pause(); videosource.setAttribute('src', adBlockerVideoMap[currSelected][1]); videocontainer.load(); videocontainer.play(); lastSelected = currSelected; }

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences