Program to left rotate the elements of an array17 Mar 2025 | 2 min read In this program, we need to rotate the elements of an array towards the left by the specified number of times. In the left rotation, each element of the array will be shifted to its left by one position and the first element of the array will be added to end of the list. This process will be followed for a specified number of times. ![]() Consider above array, if n is 1 then, all elements of the array will be moved to its left by one position such that second element of the array will take the first position, the third element will be moved to the second position and so on. The first element of the array will be added to the last of the array. Algorithm
Program:Output: Original Array: 1 2 3 4 5 Array after left rotation: 4 5 1 2 3 Next TopicJava Programs |
It is a problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going to solve...
4 min read
In this program, we need to multiply two matrices and print the resulting matrix. Product of two matrices The product of two matrices can be computed by multiplying elements of the first row of the first matrix with the first column of the second matrix then, add...
6 min read
Java Convert Object to String We can convert Object to String in java using toString() method of Object class or String.valueOf(object) method. You can convert any object to String in java whether it is user-defined class, StringBuilder, StringBuffer or anything else. Here, we are going to see two examples...
1 min read
Java Convert int to long We can convert int to long in java using assignment operator. There is nothing to do extra because lower type can be converted to higher type implicitly. It is also known as implicit type casting or type promotion. Java int to long Example Let's...
1 min read
In this program, we will create a doubly linked list and remove the duplicate, if present, by traversing through the list. Original List: List after removing duplicates: In above list, node2 is repeated thrice, and node 3 is repeated twice. Current will point to head, and index will...
7 min read
Matrix Programs Matrix relates to mathematics that can be defined as a 2-dimensional array in the form of a rectangle which is filled either with numbers or symbols or expressions as its elements. The matrix has a row and column arrangement of its elements. A matrix with...
1 min read
In Java, there are many ways to swap two numbers. Generally, we use either swap() method of the Math class or use a third (temporary) variable to swap two numbers. Except these two ways, we can also swap two numbers using the bitwise operator (XOR) and...
3 min read
Java Program to find Second Largest Number in an Array We can find the second largest number in an array in java by sorting the array and returning the 2nd largest number. Let's see the full example to find the second largest number in java array. public...
3 min read
It is very interesting problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going to...
2 min read
In this program, we need to swap two strings without using a third variable. Str1: Good Str2: morning Swapping two strings usually take a temporary third variable. One of the approach to accomplish this is to concatenate given two strings into first string. Str1Str1 = Str1 + Str2=...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India