Posts

Showing posts from February, 2022
 Shell Sort Implementation program in Java https://github.com/cbsingh1/DailyCodingProblems/blob/main/src/main/java/com/cbsingh/sorting/ShellSortImpl.java
Selection Sort with Implementation In Java In-place algorithm Time complexity : O(n2)  - Quadratic Unstable Algorithm https://github.com/cbsingh1/DailyCodingProblems/blob/084a452784a1002afe186907f0216f7a7d34edfe/src/main/java/com/cbsingh/sorting/SelectionSortImpl.java import java.util.Arrays; public class SelectionSortImpl { public static int [] sort( int arr[]) { for ( int lastUnsortedIndex= arr. length - 1 ; lastUnsortedIndex > 0 ; lastUnsortedIndex--) { int maxIndex = 0 ; for ( int i = 1 ; i <=lastUnsortedIndex ; i++) { if (arr[i] > arr[maxIndex]) maxIndex = i; } swap (arr, maxIndex, lastUnsortedIndex); } return arr; } private static void swap( int [] arr, int i, int j) { if (i == j) return ; int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } public static void main(String[] args) { int arr1[] = { 20 , ...

Max Number of Coins (Coding Problem By Zillow)

  You are given a 2-d matrix  where each cell represents number of coins in that cell. Assuming we start at matrix[0][0] , and can only move right or down, find the maximum number of coins you can collect by the bottom right corner. For example, in this matrix 0 3 1 1 2 0 0 4 1 5 3 1 The most we can collect is 0 + 2 + 1 + 5 + 3 + 1 = 12 coins. Solution:   https://github.com/cbsingh1/DailyCodingProblems/blob/main/src/main/java/MaxCoinCollector_838.java public class MaxCoinCollector_838 { static int findMaxCoins( int coinMatrix[][]) { if (coinMatrix == null ) return 0 ; int rows = coinMatrix. length ; int columns = coinMatrix[ 0 ]. length ; int [][] tempMatrix = new int [rows] [columns]; tempMatrix[ 0 ] [ 0 ] = coinMatrix[ 0 ] [ 0 ]; for ( int c = 1 ; c < columns; c++) tempMatrix[ 0 ] [c] = tempMatrix[ 0 ] [c - 1 ] + coinMatrix[ 0 ] [c]; for ( int r = 1 ; r < rows; r++) tempMatrix[...