Array
- 29 September
find transpose of a matrix in java
If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions. In this post, we will see how to find transpose of matrix in java. Transpose of matrix? A matrix which is created by converting all the rows of a given matrix into columns and vice-versa. Below […]
- 06 October
Maximum difference between two elements such that larger element appears after the smaller number
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. Given array of integers, find Maximum difference between two elements such that larger element appears after the smaller number For example: [crayon-62b8f0874afbf602183165/] Algorithm: Lets say we have array arr[] of stock prices. We will track two variable :minElementTillNow and maxDifference. minElementTillNow will be […]
- 03 October
Stock Buy Sell to Maximize Profit
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. Given an array of integers representing stock price on a single day, find max profit that can be earned by 1 transaction. So you need to find a pair (buyDay,sellDay) where buyDay < = sellDay and it […]
- 28 September
Minimum number of platforms required for a railway station
If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions. Problem: You are given arrival and departure time of trains reaching to a particular station. You need to find minimum number of platforms required to accommodate the trains at any point of time. For example: [crayon-62b8f0874bb7b857471551/] […]
- 02 February
Rotate an array by K positions
In this tutorial, we will see how to rotate an array be K positions. Problem: N=6 and k=2 If Arr[] = {1, 2, 3, 4, 5, 6} and k=2 then [rotated array](https://java2blog.com/search-element-in-sorted-and-rotated-array-java/ “rotated array”) will be {5, 6, 1, 2, 3, 4} Solution: There are multiple ways to solve this problem. Approach 1: Move each […]
- 03 October
Search in a row wise and column wise sorted matrix
If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions. If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions. Problem : Given row wise and column wise sorted matrix ,we need to search element with minimum […]
- 15 October
Largest sum contiguous subarray
If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. Problem: From Wikipedia : In computer science, the Largest sum contiguous subarray is the task of finding the contiguous subarray within a one-dimensional array of numbers which has the largest sum. For example, for the sequence of […]
- 06 October
Find the Contiguous Subarray with Sum to a Given Value in an array
Problem : Given an array of positive integer and given value X, find Contiguous sub array whose sum is equal to X. For example: [crayon-62b8f0874d0f7043149847/] Solution: Solution 1: Check all sub arrays and if current sum is equal to X, return. This will require two loops and if currentSum is greater than X tben try […]
- 06 October
Separate 0s and 1s in an array
Problem : Given an array of 0’s and 1’s in random order , you need to separate 0’s and 1’s in an array. For example: [crayon-62b8f0874d5d1680098976/] Solution : Solution 1: Count number of 0’s in the array. Lets say we get X 0’s Once we get the count, put X 0’s in the array and […]