The Wayback Machine - https://web.archive.org/web/20240930225309/https://www.geeksforgeeks.org/rotate-bits-of-an-integer/
Open In App

Rotate bits of a number

Last Updated : 13 Dec, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow
Show Topics
Solve Problem
Easy
20.8%
83.7K

Bit Rotation: A rotation (or circular shift) is an operation similar to shift except that the bits that fall off at one end are put back to the other end. 
In left rotation, the bits that fall off at left end are put back at right end. 
In right rotation, the bits that fall off at right end are put back at left end.
 

Recommended Practice

Example: 
Let n is stored using 8 bits. Left rotation of n = 11100101 by 3 makes n = 00101111 (Left shifted by 3 and first 3 bits are put back in last ). If n is stored using 16 bits or 32 bits then left rotation of n (000…11100101) becomes 00..0011100101000. 
Right rotation of n = 11100101 by 3 makes n = 10111100 (Right shifted by 3 and last 3 bits are put back in first ) if n is stored using 8 bits. If n is stored using 16 bits or 32 bits then right rotation of n (000…11100101) by 3 becomes 101000..0011100. 
 

C++




// C++ code to rotate bits
// of number
#include<iostream>
 
using namespace std;
#define INT_BITS 32
class gfg
{
     
/*Function to left rotate n by d bits*/
public:
int leftRotate(int n, unsigned int d)
{
     
    /* In n<<d, last d bits are 0. To
     put first 3 bits of n at
    last, do bitwise or of n<<d
    with n >>(INT_BITS - d) */
    return (n << d)|(n >> (INT_BITS - d));
}
 
/*Function to right rotate n by d bits*/
int rightRotate(int n, unsigned int d)
{
    /* In n>>d, first d bits are 0.
    To put last 3 bits of at
    first, do bitwise or of n>>d
    with n <<(INT_BITS - d) */
    return (n >> d)|(n << (INT_BITS - d));
}
};
 
/* Driver code*/
int main()
{
    gfg g;
    int n = 16;
    int d = 2;
    cout << "Left Rotation of " << n <<
            " by " << d << " is ";
    cout << g.leftRotate(n, d);
    cout << "\nRight Rotation of " << n <<
            " by " << d << " is ";
    cout << g.rightRotate(n, d);
    getchar();
}
 
// This code is contributed by SoM15242


C




#include<stdio.h>
#define INT_BITS 32
 
/*Function to left rotate n by d bits*/
int leftRotate(int n, unsigned int d)
{
   /* In n<<d, last d bits are 0. To put first 3 bits of n at
     last, do bitwise or of n<<d with n >>(INT_BITS - d) */
   return (n << d)|(n >> (INT_BITS - d));
}
 
/*Function to right rotate n by d bits*/
int rightRotate(int n, unsigned int d)
{
   /* In n>>d, first d bits are 0. To put last 3 bits of at
     first, do bitwise or of n>>d with n <<(INT_BITS - d) */
   return (n >> d)|(n << (INT_BITS - d));
}
 
/* Driver program to test above functions */
int main()
{
  int n = 16;
  int d = 2;
  printf("Left Rotation of %d by %d is ", n, d);
  printf("%d", leftRotate(n, d));
  printf("\nRight Rotation of %d by %d is ", n, d);
  printf("%d", rightRotate(n, d));
  getchar();
}


Java




// Java code to rotate bits
// of number
import java.io.*;
class GFG
{
static final int INT_BITS = 32;
 
/*Function to left rotate n by d bits*/
static int leftRotate(int n, int d) {
     
    /* In n<<d, last d bits are 0.
       To put first 3 bits of n at
       last, do bitwise or of n<<d with
       n >>(INT_BITS - d) */
    return (n << d) | (n >> (INT_BITS - d));
}
 
/*Function to right rotate n by d bits*/
static int rightRotate(int n, int d) {
     
    /* In n>>d, first d bits are 0.
       To put last 3 bits of at
       first, do bitwise or of n>>d
       with n <<(INT_BITS - d) */
    return (n >> d) | (n << (INT_BITS - d));
}
 
// Driver code
public static void main(String arg[])
{
    int n = 16;
    int d = 2;
    System.out.print("Left Rotation of " + n +
                          " by " + d + " is ");
    System.out.print(leftRotate(n, d));
     
    System.out.print("\nRight Rotation of " + n +
                             " by " + d + " is ");
    System.out.print(rightRotate(n, d));
}
}
 
// This code is contributed by Anant Agarwal.


Python3




# Python3 code to
# rotate bits of number
 
INT_BITS = 32
 
# Function to left
# rotate n by d bits
def leftRotate(n, d):
 
    # In n<<d, last d bits are 0.
    # To put first 3 bits of n at
    # last, do bitwise or of n<<d
    # with n >>(INT_BITS - d)
    return (n << d)|(n >> (INT_BITS - d))
 
# Function to right
# rotate n by d bits
def rightRotate(n, d):
 
    # In n>>d, first d bits are 0.
    # To put last 3 bits of at
    # first, do bitwise or of n>>d
    # with n <<(INT_BITS - d)
    return (n >> d)|(n << (INT_BITS - d)) & 0xFFFFFFFF
 
# Driver program to
# test above functions
n = 16
d = 2
 
print("Left Rotation of",n,"by"
      ,d,"is",end=" ")
print(leftRotate(n, d))
 
print("Right Rotation of",n,"by"
     ,d,"is",end=" ")
print(rightRotate(n, d))
 
# This code is contributed by
# Smitha Dinesh Semwal


C#




// C# program to rotate
// bits of a number
using System;
 
class GFG
{
    static int INT_BITS = 32;
 
    /* Function to left rotate n by d bits*/
    static int leftRotate(int n, int d) {
         
        /* In n<<d, last d bits are 0.
        To put first 3 bits of n at
        last, do bitwise or of n<<d with
        n >>(INT_BITS - d) */
        return (n << d) | (n >> (INT_BITS - d));
    }
     
    /*Function to right rotate n by d bits*/
    static int rightRotate(int n, int d) {
         
        /* In n>>d, first d bits are 0.
        To put last 3 bits of at
        first, do bitwise or of n>>d
        with n <<(INT_BITS - d) */
        return (n >> d) | (n << (INT_BITS - d));
    }
     
    // Driver code
    public static void Main()
    {
        int n = 16;
        int d = 2;
         
        Console.Write("Left Rotation of " + n
                      + " by " + d + " is ");
        Console.Write(leftRotate(n, d));
         
        Console.Write("\nRight Rotation of " + n
                       + " by " + d + " is ");
        Console.Write(rightRotate(n, d));
    }
}
 
// This code is contributed by Sam007


Javascript




<script>
 
// JavaScript code to rotate bits
// of number
let INT_BITS = 32;
 
     
/*Function to left rotate n by d bits*/
 
function leftRotate( n,  d)
{   
    /* In n<<d, last d bits are 0. To
     put first 3 bits of n at
    last, do bitwise or of n<<d
    with n >>(INT_BITS - d) */
    return (n << d)|(n >> (INT_BITS - d));
}
 
/*Function to right rotate n by d bits*/
function rightRotate( n, d)
{
    /* In n>>d, first d bits are 0.
    To put last 3 bits of at
    first, do bitwise or of n>>d
    with n <<(INT_BITS - d) */
    return (n >> d)|(n << (INT_BITS - d));
}
 
 
/* Driver code*/
let n = 16;
let d = 2;
document.write("Left Rotation of " + n +
            " by " + d + " is ");
document.write(leftRotate(n, d));
document.write("<br>");           
document.write("\nRight Rotation of " + n +
            " by " + d + " is ");
document.write(rightRotate(n, d));
 
</script>


Output

Left Rotation of 16 by 2 is 64
Right Rotation of 16 by 2 is 4

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

For 16 bit number:

C++




#include <bits/stdc++.h>
 
using namespace std;
 
#define SHORT_SIZE 16
 
// function to rotate the given unsigned short
// in the left direction
unsigned short leftRotate(unsigned short x, short d)
{
    /**
     * By doing x << d, we move the first(right most) d bits
     * to the left most d bits, and at the same time we move
     * the left most d bits to the right side,
     * performing OR operation between the two gives use the
     * required result.
     * */
 
    return (x << d) | (x >> (SHORT_SIZE - d));
}
 
// function to rotate the given unsigned short
// in the right direction
unsigned short rightRotate(unsigned short x, short d)
{
    /**
     * By doing x >> d, we move the first(left most) d bits
     * to the right most d bits, and at the same time we move
     * the right most d bits to the right side,
     * performing OR operation between the two gives use the
     * required result.
     * */
 
    return (x >> d) | (x << (SHORT_SIZE - d));
}
 
/* Driver program to test above functions */
int main()
{
    // Test case
    unsigned short n = 28;
    short d = 2;
 
    cout << leftRotate(n, d) << endl;
    cout << rightRotate(n, d) << endl;
 
    return 0;
}
 
// This code is contributed by ganesh227


C




#include <stdio.h>
#define SHORT_SIZE 16
 
// function to rotate the given unsigned short
// in the left direction
unsigned short leftRotate(unsigned short x, short d)
{
    /**
     * By doing x << d, we move the first(right most) d bits
     * to the left most d bits, and at the same time we move
     * the left most d bits to the right side,
     * performing OR operation between the two gives use the
     * required result.
     * */
 
    return (x << d) | (x >> (SHORT_SIZE - d));
}
 
// function to rotate the given unsigned short
// in the right direction
unsigned short rightRotate(unsigned short x, short d)
{
    /**
     * By doing x >> d, we move the first(left most) d bits
     * to the right most d bits, and at the same time we move
     * the right most d bits to the right side,
     * performing OR operation between the two gives use the
     * required result.
     * */
 
    return (x >> d) | (x << (SHORT_SIZE - d));
}
 
/* Driver program to test above functions */
int main()
{
    // Test case
    unsigned short n = 28;
    short d = 2;
    printf("%d\n", leftRotate(n, d));
    printf("%d\n", rightRotate(n, d));
 
    return 0;
}
 
// This code is contributed by ganesh227


Java




/*package whatever //do not write package name here */
 
import java.io.*;
 
class GFG {
    public static void main (String[] args) {
        int N=28;
          int D=2;
          rotate(N,D);
    }
   
   static void rotate(int N, int D)
    {
        // your code here
        int t=16;
        int left= ((N<<D) | N>>(t-D)) & 0xFFFF;
        int right=((N>>D) | N<<(t-D)) & 0xFFFF;
        System.out.println(left);
         System.out.println(right);
    }
   
}


Python3




SHORT_SIZE = 16
 
# function to rotate the given unsigned short
# in the left direction
def leftRotate(x, d):
 
    return (x << d) | (x >> (SHORT_SIZE - d))
 
  # function to rotate the given unsigned short
# in the right direction
def rightRotate(x, d):
 
    return (x >> d) | (x << (SHORT_SIZE - d)) & 0xDDDDDF
 
# Driver program to test above functions
# Test case
n = 28
d = 2
 
print("Left Rotation of",n,"by"
      ,d,"is",end=" ")
print(leftRotate(n, d))
 
print("Right Rotation of",n,"by"
     ,d,"is",end=" ")
print(rightRotate(n, d))
 
# This code is contributed by shivanisinghss2110


C#




/*package whatever //do not write package name here */
using System;
using System.Collections.Generic;
public class GFG {
    public static void Main(String[] args) {
        int N = 28;
          int D = 2;
          rotate(N, D);
    }
   
  // Driver code
   static void rotate(int N, int D)
    {
        int t = 16;
        int left = ((N<<D) | N>>(t-D)) & 0xFFFF;
        int right = ((N>>D) | N<<(t-D)) & 0xFFFF;
        Console.WriteLine(left);
         Console.WriteLine(right);
    }
   
}
 
// This code is contributed by umadevi9616


Javascript




<script>
 
function rotate(N,D)
{
    // your code here
        let t = 16;
        let left = ((N<<D) | N>>(t-D)) & 0xFFFF;
        let right = ((N>>D) | N<<(t-D)) & 0xFFFF;
        document.write(left + "<br>");
         document.write(right + "<br>");
}
 
let N = 28;
let D = 2;
rotate(N, D);
 
// This code is contributed by avanitrachhadiya2155
</script>


Output

112
7

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

Please write comments if you find any bug in the above program or other ways to solve the same problem. 
 



Previous Article
Next Article

Similar Reads

Toggle bits of a number except first and last bits
Given a number, the task is to toggle bits of the number except the first and the last bit.Examples: Input : 10 Output : 12 Binary representation:- 1 0 1 0 After toggling first and last : 1 1 0 0 Input : 9 Output : 15 Binary representation : 1 0 0 1 After toggling first and last : 1 1 1 1 Prerequisite: Find most significant set bit of a number Gene
8 min read
Check if bits of a number has count of consecutive set bits in increasing order
Given a integer n > 0, the task is to find whether in the bit pattern of integer count of continuous 1's are in increasing from left to right. Examples : Input:19 Output:Yes Explanation: Bit-pattern of 19 = 10011, Counts of continuous 1's from left to right are 1, 2 which are in increasing order. Input : 183 Output : yes Explanation: Bit-pattern
11 min read
Check if all bits can be made same by flipping two consecutive bits
Given a binary string, the task is to find whether all the digits of the string can be made equal i.e either 0 or 1 by flipping two consecutive bits any number of times.Examples: Input: 01011Output: YESExplanation:Flip 2nd and 3rd bit -> 00111, again flipping 1'st and 2'nd bit -> 11111 Input: 100011Output: NOExplanation:No number of moves can
5 min read
Flip bits of the sum of count of set bits of two given numbers
Given two numbers A and B, the task is to count the number of set bits in A and B and flip the bits of the obtained sum. Examples: Input: A = 5, B = 7Output: 2Explanation:Binary representation of A is 101.Binary representation of B is 111.Count of set bits in A and B = 2 + 3 = 5.Binary representation of the sum obtained = 101Flipping the bits of th
5 min read
Minimize cost of swapping set bits with unset bits in a given Binary string
Given a binary string S of size N, the task is to find the minimum cost by swapping every set bit with an unset bit such that the cost of swapping pairs of bits at indices i and j is abs(j - i). Note: A swapped bit can't be swapped twice and the count of set bit in the given binary string is at most N/2. Examples: Input: S = "1010001"Output: 3Expla
12 min read
Count of pairs {X, Y} from an array such that sum of count of set bits in X ⊕ Y and twice the count of set bits in X & Y is M
Given an array arr[] consisting of N non-negative integers and an integer M, the task is to find the count of unordered pairs {X, Y} of array elements that satisfies the condition setBits(X ⊕ Y) + 2 * setBits(X & Y) = M, where ⊕ denotes the Bitwise XOR and & denotes the Bitwise AND. Examples: Input: arr[] = {30, 0, 4, 5 }, M = 2Output: 2Exp
14 min read
Print numbers having first and last bits as the only set bits
Given a positive integer n. The problem is to print numbers in the range 1 to n having first and last bits as the only set bits.Examples: Input : n = 10 Output : 1 3 5 9 (1)10 = (1)2. (3)10 = (11)2. (5)10 = (101)2. (9)10 = (1001)2 Naive Approach: Print "1". Now for i = 3 to n, check if (i-1) is a Perfect power of two or not. If true then print i. C
10 min read
Javascript Program to Rotate digits of a given number by K
Given two integers N and K, the task is to rotate the digits of N by K. If K is a positive integer, left rotate its digits. Otherwise, right rotate its digits. Examples: Input: N = 12345, K = 2Output: 34512 Explanation: Left rotating N(= 12345) by K(= 2) modifies N to 34512. Therefore, the required output is 34512 Input: N = 12345, K = -3Output: 34
2 min read
Rotate digits of a given number by K
Given two integers N and K, the task is to rotate the digits of N by K. If K is a positive integer, left rotate its digits. Otherwise, right rotate its digits. Examples: Input: N = 12345, K = 2Output: 34512 Explanation: Left rotating N(= 12345) by K(= 2) modifies N to 34512. Therefore, the required output is 34512 Input: N = 12345, K = -3Output: 34
10 min read
Minimum number using set bits of a given number
Given an unsigned number, find the minimum number that could be formed by using the bits of the given unsigned number. Examples : Input : 6 Output : 3 Binary representation of 6 is 0000....0110. Smallest number with same number of set bits 0000....0011. Input : 11 Output : 7 Simple Approach: 1. Find binary representation of the number using simple
4 min read
Check if a number has same number of set and unset bits
Given a number N, the task is to check whether the count of the set and unset bits in the given number are same. Examples: Input: 12Output: Yes1100 is the binary representation of 12which has 2 set and 2 unset bits Input: 14Output: No Approach: Traverse in the binary representation of the given number, check if the leftmost bit is set or not using
5 min read
Maximum number of contiguous array elements with same number of set bits
Given an array with n elements. The task is to find the maximum number of contiguous array elements which have the same number of set bits. Examples: Input : arr[] = {14, 1, 2, 32, 12, 10} Output : 3 Elements 1, 2, 32 have same number of set bits and are contiguous. Input : arr[] = {1, 6, 9, 15, 8} Output : 2 Elements 6, 9 have same number of set b
6 min read
Calculate the number of set bits for every number from 0 to N
Given a non-negative integer N, the task is to find the count of set bits for every number from 0 to N.Examples: Input: N = 3 Output: 0 1 1 2 0, 1, 2 and 3 can be written in binary as 0, 1, 10 and 11. The number of 1's in their binary representation are 0, 1, 1 and 2.Input: N = 5 Output: 0 1 1 2 1 2 Naive approach: Run a loop from 0 to N and using
9 min read
Find the largest number smaller than integer N with maximum number of set bits
Given an integer N, the task is to find the largest number smaller than N having the maximum number of set bits.Examples: Input : N = 345 Output : 255 Explanation: 345 in binary representation is 101011001 with 5 set bits, and 255 is 11111111 with maximum number of set bits less than the integer N.Input : N = 2 Output : 1 Explanation: 2 in binary r
8 min read
Next higher number with same number of set bits
Given a number x, find next number with same number of 1 bits in it's binary representation.For example, consider x = 12, whose binary representation is 1100 (excluding leading zeros on 32 bit machine). It contains two logic 1 bits. The next higher number with two logic 1 bits is 17 (100012).Algorithm:When we observe the binary sequence from 0 to 2
8 min read
M-th smallest number having k number of set bits.
Given two non-negative integers m and k. The problem is to find the m-th smallest number having k number of set bits.Constraints: 1 <= m, k.Examples: Input : m = 4, k = 2 Output : 9 (9)10 = (1001)2, it is the 4th smallest number having 2 set bits. Input : m = 6, k = 4 Output : 39 Approach: Following are the steps: Find the smallest number having
6 min read
Number of integers with odd number of set bits
Given a number n, count number of integers smaller than or equal to n that have odd number of set bits.Examples: Input : 5 Output : 3 Explanation : Integers with odd number of set bits in range 1 to 5 : 0 contains 0 set bits 1 contains 1 set bits 2 contains 1 set bits 3 contains 2 set bits 4 contains 1 set bits 5 contains 2 set bits Input : 10 Outp
6 min read
Rotate a Matrix by 180 degree
Given a square matrix, the task is that we turn it by 180 degrees in an anti-clockwise direction without using any extra space. Examples : Input : 1 2 3 4 5 6 7 8 9 Output : 9 8 7 6 5 4 3 2 1 Input : 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 Output : 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 Method: 1 (Only prints rotated matrix) The solution of this problem is that t
15+ min read
String slicing in Python to Rotate a String
Given a string of size n, write functions to perform following operations on string. Left (Or anticlockwise) rotate the given string by d elements (where d <= n).Right (Or clockwise) rotate the given string by d elements (where d <= n).Examples: Input : s = "GeeksforGeeks" d = 2Output : Left Rotation : "eksforGeeksGe" Right Rotation : "ksGeek
3 min read
Rotate the matrix right by K times
Given a matrix of size N*M, and a number K. We have to rotate the matrix K times to the right side. Examples: Input : N = 3, M = 3, K = 2 12 23 34 45 56 67 78 89 91 Output : 23 34 12 56 67 45 89 91 78 Input : N = 2, M = 2, K = 2 1 2 3 4 Output : 1 2 3 4 A simple yet effective approach is to consider each row of the matrix as an array and perform an
9 min read
Rotate a matrix by 90 degree in clockwise direction without using any extra space
Given a square matrix, turn it by 90 degrees in a clockwise direction without using any extra space. Examples: Input: 1 2 3 4 5 6 7 8 9 Output: 7 4 1 8 5 2 9 6 3 Input: 1 2 3 4 Output: 3 1 4 2 Method 1 Approach: The approach is similar to Inplace rotate square matrix by 90 degrees | Set 1. The only thing that is different is to print the elements o
15+ min read
Rotate the sub-list of a linked list from position M to N to the right by K places
Given a linked list and two positions 'm' and 'n'. The task is to rotate the sublist from position m to n, to the right by k places.Examples: Input: list = 1->2->3->4->5->6, m = 2, n = 5, k = 2 Output: 1->4->5->2->3->6 Rotate the sublist 2 3 4 5 towards right 2 times then the modified list are: 1 4 5 2 3 6 Input: list
13 min read
Python | Ways to rotate a list
The rotation of a list has been discussed earlier also, but this particular article focuses on shorthands and various short techniques to achieve this in one-liners or one word. This operation is quite essential in a programmer's life to achieve various tasks. Let's discuss different ways we can rotate a list in Python. Method 1: Rotate a list usin
8 min read
Rotate matrix by 45 degrees
Given a matrix mat[][] of size N*N, the task is to rotate the matrix by 45 degrees and print the matrix. Examples: Input: N = 6, mat[][] = {{3, 4, 5, 1, 5, 9, 5}, {6, 9, 8, 7, 2, 5, 2}, {1, 5, 9, 7, 5, 3, 2}, {4, 7, 8, 9, 3, 5, 2}, {4, 5, 2, 9, 5, 6, 2}, {4, 5, 7, 2, 9, 8, 3}}Output: 3 6 4 1 9 5 4 5 8 1 4 7 9 7 54 5 8 7 2 9 5 2 9 5 5 7 9 3 3 2 5 5
15+ min read
Rotate-matrix module in Python
The rotate-matrix is an interesting new python module, which allows conversion of a matrix(2-D array) into either clockwise rotation or anti-clockwise rotation. It at present consists of only two methods. You can loop through these methods for 'n' number of rotations. Installation This module doesn't come in-built with python but can be installed u
1 min read
Left rotate digits of node values of all levels of a Binary Tree in increasing order
Given a Binary Tree, the task is to modify the Tree by left rotating every node any number of times such that every level consists of node values in increasing order from left to right. If it is not possible to arrange node values of any level in increasing order, then print "-1". Examples: Input: 341 / \ 241 123 / \ \ 324 235 161Output: 341 / \ 12
14 min read
Rotate all Matrix elements except the diagonal K times by 90 degrees in clockwise direction
Given a square matrix mat[][] of dimension N and an integer K, the task is to rotate the matrix by 90 degrees K times without changing the position of the diagonal elements. Examples: Input: mat[][] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}, {21, 22, 23, 24, 25}}, K = 1Output: 1 16 11 6 5 22 7 12 9 2 23 18 13
10 min read
Javascript Program to Rotate all odd numbers right and all even numbers left in an Array of 1 to N
Given a permutation arrays A[] consisting of N numbers in range [1, N], the task is to left rotate all the even numbers and right rotate all the odd numbers of the permutation and print the updated permutation. Note: N is always even.Examples:  Input: A = {1, 2, 3, 4, 5, 6, 7, 8} Output: {7, 4, 1, 6, 3, 8, 5, 2} Explanation: Even element = {2, 4, 6
2 min read
Right rotate given Array K times using Pointers
Given an array arr[] of size N and an integer K, the task is to right rotate the array K times. Examples: Input: arr[] = {1, 3, 5, 7, 9}, K = 2Output: 7 9 1 3 5Explanation: After 1st rotation - {9, 1, 3, 5, 7}After 2nd rotation - {7, 9, 1, 3, 5} Input: {1, 2, 3, 4, 5, 6}, K = 2Output: 5 6 1 2 3 4 Approach: The naive approach and approach based on r
6 min read
Left rotate Linked List by X in groups of Y nodes
Given a singly linked list and two integers X and Y, the task is to left rotate the linked list by X in groups of Y nodes. Examples: Input: 10 -> 20 -> 30 -> 40 -> 50 -> 60 -> 70 -> 80 -> 90 -> 100, X = 2, Y = 4Output: 30 -> 40 -> 10 -> 20 -> 70 -> 80 -> 50 -> 60 -> 90 -> 100Explanation: First g
10 min read
Article Tags :
Practice Tags :