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.
Tuesday, July 1, 2025
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.
Labels:
Coding problems
,
homework
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.
Labels:
Coding Interview Question
,
Coding problems
,
Triangle
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?
Labels:
Array
,
Coding Interview Question
,
Coding problems
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.
Labels:
coding
,
Coding Interview Question
,
Coding problems
,
core java
,
programming
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.
Labels:
coding
,
Coding Interview Question
,
Coding problems
,
core java
,
programming
Top 10 Dynamic Programming Problems from Coding Interviews
Dynamic Programming is one of the toughest concepts to master for programmers but at the same time, it's quite important to crack any programming job interviews. Nowadays, you will find at least one Dynamic programming coding problem on every coding interview and that's
where most of the programmers get stuck. They try to solve the problem using techniques like divide and conquer but ultimately fail because it's difficult to come to a solution to such problems unless you have solved a decent number of dynamic
programming-based coding questions. This is very similar to system design questions which look easy but when you try to solve them you often find yourself stuck and that's why I suggest you practice as much as possible.
Labels:
Coding problems
,
Dynamic Programming
,
interview questions
How to check if a given Tree is a Binary Search Tree in Java? Example Tutorial
Hello guys, if you are preparing for a coding interview then you may know those binary tree problems are not easy to solve on coding interviews and I have seen many candidates struggling to do post-order traversal and checking if a given binary tree is a binary search tree or not. If you want to succeed in the coding interview, you need to prepare well on binary trees in general. One way to prepare better is solving common binary tree coding problems like this one, where you need to find if the given tree is BST or not. There are a lot of things that would tell us if a tree is a binary search tree. But before we get to that, we need to understand what a binary tree is.
Radix sort in Java with Example
Hello guys, in one of the interview I was asked to name any O(n) sorting algorithm. I was shocked because I only knew about QuickSort and Mergesort whose best time is O(NLogN), so I couldn't answer that question. After the interview, the first thing I did was to Google about O(n) sorting algorithm and I was surprised to find that there are many algorithms like Radix Sort and Counting Sort and Bucket Sort which can provide O(n) performance. So, I learn them and wrote articles about them like in previous article I explained about Counting Sort algorithm and in this article, I will explain Radis sort like what it is and how it works. In Radix sort, we are sorting by comparing individual digits from the last one to the first one. In essence, radix sort is like this: sort elements by the last digit.
Labels:
coding
,
data structure and algorithm
,
programming
,
Sorting algorithm
How to check if a String has all unique characters in Java? [Solved]
Hello guys, its been long time since I shared any interesting coding problem but the wait is over. Today, I am going to share one interesting and popular String based coding problem which you would love to solve. Today's coding challenge is to find out if a given string has all unique characters or not, for example, if given String is "Java" then your function should return false because all styles from this String are not unique. On the other hand, if the given String is "Python," then your function should return true because all characters are unique in this String. Btw, don't just jump on the solution if this is ever asked to you on Interview; instead, you should ask a couple of good questions to demonstrate your requirement gathering skill and attention for details.
Labels:
Coding problems
,
data structure and algorithm
,
String
5 ways to find length of String in Java - Example Tutorial
On another day, someone asked me, is there a way to find the length of String without using the length() method from java.lang.String class? I didn't ask why, because I know it might have been asked to him on Interviews. Before I explore ways to find the length of String, let's recap what does the length of String means in Java? Well, it's no different than C here, a number of characters in a String including whitespace, newlines are known as length of String. By knowing this, you can think of many approaches to calculating length e.g. getting a char array from String and counting a number of characters or many are by applying some clever tricks.
Labels:
core java
,
data structure and algorithm
,
String
How to implement Linear Search in Java? Example Tutorial
Hello guys, earlier, I have talked about how the binary search algorithm works and shared the code to implement the binary search in Java. In that article, someone asked me about is there any other search algorithm that exists? How can you search an element in the array if it's not sorted, and you cannot use the binary search algorithm? To answer his questions, I mentioned the Linear search algorithm, which is the predecessor of binary search. Generally, it is taught before the binary search algorithm because the binary search is faster than Linear search. However, never mind, you can still learn this useful algorithm to search for an item in the array or linked list.
Labels:
core java
,
data structure and algorithm
How to Find Square Root of a Number in Java? Example Solution
Write a program to calculate the square root of a number in Java or C++ is one of the popular coding interview questions from Programming job interviews both on tech companies like Facebook, Amazon, and investment banks like Citibank and Bank Of America, etc. The problem may look easy because you might know how to find the square root of a number but it's not. In fact, it's one of the tricky questions you would encounter in programming job interviews. The first hurdle is do you really remember how to calculate square root by hand? Many programmers don't. I know they have learned it past but when you ask them to calculate square root by hand, many won't remember the algorithm they have learned in school or college.
Counting Sort Algorithm in Java? Example Tutorial
Hello guys, in our last article, we looked at the Radix Sort in Java and in this article, we will look at the counting sort in Java. If you are thinking how they are related then let me tell you that both are O(n) sorting algorithms. Yes, its possible to sort in O(n) or linear time. If you are wondering that you have so far only learned that best sorting algorithms are Quick Sort and Merge Sort who sorts an array in O(nLogN) time then you are in for surprise. Yes, there existing O(n) sorting algorithms which are faster than both Quicksort and Merge sort like Radix Sort, Counting Sort, and Bucket Sort but they have their limitation. They are not general purpose sorting algorithm and you can use this to sort only integers and it also depends upon how big is the data set and how many different numbers are in the data set.
Labels:
core java
,
data structure and algorithm
,
Sorting algorithm
Subscribe to:
Posts
(
Atom
)