Thursday, July 3, 2025

How to merge two sorted arrays in Java? Example Tutorial

Hello guys, if you want to learn how to merge two sorted arrays in Java then you have come to the right place. Earlier, I have shown you how to sort arrays in Javaand in this article, I will show you how to merge two sorted arrays in Java. Btw, if you are a complete beginner then Firstly, you need to know what an array is before going about solving this problem about sorted array.  An array is a data structure in Java that holds values of the same type with its length specified right from creation time. This means you can create an integer array like int[] to store integer value. Think of a container, like a crate of eggs or coke, where number of places are fixed and you cannot change once you created it.

How to check if a given linked list is a palindrome in Java? Example [Solved]

Hello guys, if you are wondering how to check if a given linked list is a palindrome in Java then you have come to the right place. In the past, I have shared how to check if a given String is palindrome or a given number is a palindrome, and in this article, I will teach you how to check if a linked list is a palindrome. But before that, let's revise what is a palindrome? A palindrome is a phrase, word or number, or other sequence of characters that reads the same backward ad forward. Meaning that It gives you the same thing when read forward or backward. For example, Mary, Army, Madam, racecar, 1-2-3-2-1, noon, level, Hannah, civic, etc.

[Solved] How to reverse a Stack in Java using Recursion and Iteration? Example Tutorial

Hello guys, if you are wondering how to reveres a stack in Java then don't go anywhere. In this article, I will show you step by step how to reverse a given stack in Java. There are two ways to reverse a stack, you can use iteration or recursion. The most common way of reversing a stack is to use an auxiliary stack. First, we will pop all the elements from the stack and push them into the auxiliary stack. Once all the elements are pushed into the auxiliary stack, then it contains the elements in the reverse order and we simply print them. But, here, we will not use the auxiliary stack. We will use a recursion method to reverse a stack where recursion means calling the function itself again and again. 

[Solved] How to Implement Fibonacci Series with Memoization in Java 8? ConcurrentHashMap Caching Example

Hello guys, if you are wondering how to solve the Fibonacci series problem with memorization in Java then you have come to the right place. In the past, I have shared recursive and iterative Fibonacci series solution and in this article, I am going to show you how you can improve your solution using a technique called memorization which uses a cache to store the intermediate results. This is a very useful technique to solve Dynamic Programming problems like the Knapsack problem. The good thing about Java is that it provides rich libraries which have classes like ConcurrentHashMap which can be used as a cache to store these intermediary results instead of re-computing them. This can drastically reduce the time to calculate the Nth Fibonacci number.

Top 20 Stack and Queue Data Structure Interview Questions for 1 to 3 years Experienced

Both Stack and Queue are two of the crucial data structure which is very useful in solving a lot of problems. They are not as fundamental data structures as an array or linked lists but they offer some unique advantages in terms of how you store and access elements. Stack is commonly known as LIFO data structure because the last element you put is the first one to come out while Queue is known as FIFO data structure. The elements are retrieved from the queue in the order they were inserted. Both of these data structure has several usages and are used to solve many common problems and to implement algorithms. 

Top 25 Recursion Interview Questions Answers for Coding Interviews

Recursion is often dreaded by programmers as its very difficult for many programmers to visualize and understand, but it's a useful problem solving technique which often result in better, simpler and more concise code than their iterative solutions. That begin said, it's often difficult to come up when to use recursion to solve a coding problem. In general, you should use recursion if a problem can be broken down into sub-problems which are exactly the same as original problem. For example, finding a node in a binary tree. If you are asked to find a node with give value in a binary tree than you can solve this with recursion. Why? because you can breakdown the problem into subproblems which are exactly the same like finding a node in binary tree is same as finding the node in left subtree and right subtree.

Top 10 Matrix Coding Exercises for Programming interviews and Homework

Hello guys, if you are preparing for Coding interviews and solved 100+ data structure problems then you may know that Matrix is one of the under-rated topic for coding interviews but Matrix coding problems are not that easy to solve and  In this article, we'll see some of the popular Matrix coding problems for coding interviews. I actually learned a lot by solving Matrix related problems. I still remember the first Matrix based problem I solve was about how to multiply two matrices in Java and I learned a lot about multi-dimensional array and nested loop in Java by solving that problem. The second problem I solved was about transposing Matrix and that was also quite challenging for me at that time but helped me to further solidify my knowledge about loops and array in Java. 

How to find first recurring or duplicate character in given String? [Solved]

Hello guys, while surfing the Internet for a couple of weeks back, I come to know that this problem was asked on Google interviews, find the first recurring character in a given String. I don't know if that's true but this looks like a very simple coding problem from Google's Interview standard. If it was indeed asked, then that guy must have been very lucky. Anyway, I liked this coding problem and thought to write about it, because it's a good coding problem to check candidates' data structure and algorithms skills because it's tricky. It's tricky because it's very easy to make a mistake assuming just one recurring character in String, which you should avoid. Even if it was not asked on Google, you will potentially find this problem on various startups, and other IT companies like Infosys, TCS, Cognizant, Microsoft, and maybe Amazon

Tuesday, July 1, 2025

[Solved] How to Find maximum Product of a sub-array in Java? Example

Hello guys, if you are asked to find maximum product of a sub-array in Java and you are wondering how to solve this difficult looking coding problem then you have come to the right place. Earlier, I have shared 30 array coding problems, 30 linked list problems, and 10 dynamic programming problems and in this article, we shall be finding the maximum product of a sub-array in java. This problem has a lot to do with arrays. But first, we'll solve the problem then we talk about Array and how it operates. The problem we are to solve here is to find the maximum product of a subarray in Java

How to calculate Area and Perimeter of Square in Java Program? Example Tutorial

Hello guys, if you are looking for Java program to calculate area of Square or program to calculate perimeter of square or just learning Java and looking for programming exercises then you have come to the right place. I have share many programming exercises and homework in this blog and today, I am going to share another simple programming assignment for beginners. Yes, we ae going to write a program which will calculate the area and perimeter of a square in Java. If you don't remember, area of a square is nothing but the multiplication of side with itself or square of side, while perimeter of a square is 4 times of its side because in case of square, each side is equal. 

How to Print a left triangle star pattern in Java? Example Tutorial

Pattern based exercises are very common on Interviews as they are tricky for beginners and also offers coding practice. In the past, I have shared article on how to print pyramid pattern of stars in Java and Pyramid pattern of albhabets, and in this article, I will show you how to print left triangle star pattern in Java. There are different ways of printing different patterns, but most of them involves using loops and print methods like print() and println() to print characters like star, alphabets or numbers. If you know how to use loops and when to break from loop then you can easily solve pattern based coding problems. 

[Solved] How to check if given point is inside Triangle or not in Java? Example

One of the interesting problem from Java Programming interviews is, "write a program to check if given point lies inside a triangle or not?". You will be given co-ordinates of vertices and the point as part of problem and you need to write a function e.g. isInside() which return true if point is within the triangle and false if it is not. For example, in the triangle specified by vertices (11, 31), (21, 1), and (1, 1) the point (11, 16) are inside the triangle and point (30,17) are outside of the triangle. It's a good coding interview question if you have not heard before, just think about how do you prove if the point lies inside the triangle or not? It's not a difficult algorithm and you can think of it by just trial and error. 

How to Rotate Array to Left or Right in Java? Example - LeetCode Solution

Hello guys, rotating an array in Java is a common coding problems which are often used to teach beginners coding as well used during interviews to check candidate's programming and data structure skills. This problem may look easy but its not that easy, especially if you are not coding regular. In order to rotate an array of n elements to the right by kth index, you need to rearrange the item in such a way that the array will start from k + 1the element.  For example, with n = 7 and k = 3, the array [1, 2, 3, 4 ,5, 6, 7] is rotated to [5, 6, 7, 1, 2, 3, 4]. See, it looks like you pick the the 4th element and rotated the array in right direction. The problem becomes even more interesting when interviewer ask you to rotate the array by left or right and in place. Could you do it in-place with O(1) extra space?

How to check Perfect number in Java? Example Tutorial

Hello guys, if you are wondering how to check if a given number is a perfect number or not in Java then you have come to the right place. This is one of the interesting coding problem to solve and learn and improve your coding and programming skill. In face, I learned most of my programming by solving these kind of questions. I started with simple ones like factorial, prime number, palindrome, anagram, string permutations before I started solving tree based problems and Dynamic programming problems. These kind of exercise not only give you a chance to get familiar with the programming language constructs like data type, operators, functions, class etc, but also help to build coding sense, which is nothing but your skill to convert your logic into code. 

How to transpose a Matrix in Java? Example Tutorial

Hello guys, if you are wondering how to transpose a matrix in Java then you have come to the right place. Matrix related coding problems are great way to learn multi-dimensional array and nested loop and they are good programming exercise for beginners. In the past, I have taught you how to multiply matrices in Java and how to add/subtract matrices in Java, and in this article, I will show you how to create transpose of a given matrix in Java, but before that let's first understand what is transpose of a matrix means and how do you transpose a matrix in maths? Well, a transpose of a matrix is nothing but a matrix whose rows and columns are reversed.