• 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-6630cdea91ce2223593789/] Algorithm: Lets say we have array arr[] of stock prices. We will track two variable :minElementTillNow and maxDifference. minElementTillNow will be […]

  • 05 October

    Separate odd and even numbers in an array

    Problem : Given an array of integers, you need to segregate odd and even numbers in an array. Please note : Order of elements can be changed. For example: [crayon-6630cdea92062046567513/] Algorithm: Lets say array is arr[] Initialise two index variable , left=0 and right=arr.length-1 Increment left variable until you get odd number Decrement right variable […]

  • 05 October

    Find leaders in an array

    Problem: We need to print all the leaders present in the array. Element is the leader if it is greater than right side of elements. For example: [crayon-6630cdea927b8700104597/] Solution: Solution 1: Use two loops. Outer loop to iterate over array elements and inner loop to check for right elements of the array. If current element […]

  • 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 […]

  • 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 […]

  • 03 October

    Find all pairs of elements from an array whose sum is equal to given number

    If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions. Problem : Given a  array,we need to find all pairs whose sum is equal to number X. For example: [crayon-6630cdea93b88016374769/] Solution : Solution 1: You can check each and every pair of numbers and find the […]

  • 01 October

    Given a sorted array and a number x, find the pair in array whose sum is closest to x

    If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions. Problem : Given a sorted array,we need to find a pair whose sum is closed to number X in Array. For example: [crayon-6630cdea941fd154982843/] Solution : Solution 1: You can check each and every pair of numbers […]

  • 01 October

    Find a Pair Whose Sum is Closest to zero in Array

    If you want to practice data structure and algorithm programs, you can go through data structure and algorithm interview questions. Problem : Given array of +ve and -ve integers ,we need to find a pair whose sum is closed to Zero in Array. For example: [crayon-6630cdea954bf722266040/] Solution : Solution 1: You can check each and every […]

  • 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 […]