Skip to content

Instantly share code, notes, and snippets.

@leosabbir
leosabbir / WordCounter.java
Last active May 14, 2018 22:04
A class to count number of words in an input string
/* File: WordCounter.java
* Created: 5/14/2018
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 Hogwart Inc.
*/
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@leosabbir
leosabbir / Shuffler.java
Created May 18, 2018 19:35
A utility class that shuffles the given array in linear time
import java.util.Random;
/**
* This is a Shuffler class that can be used to shuffle given input array
* uniformly
*
* @author Sabbir Manandhar
* @version 1.0
*/
public class Shuffler {
@leosabbir
leosabbir / MatrixShortestDistanceRecursive.java
Created May 24, 2018 20:45
Find shortest distance from a source location to a destination in a 2D matrix
/* File: MatrixShortestDistanceRecursive.java
* Created: 2017-06-28
* Author: Sabbir Manandhar
*
* Copyright (c) 2017 Hogwarts.
*/
/**
* Given a MxN matrix. Filled with 0's
* There is one source location indicated by character '*'
@leosabbir
leosabbir / MatrixShortestDistanceBFS.java
Last active May 24, 2018 20:53
Find Shortest Path from source to destination in 2D matrix using BFS method
/* File: MatrixShortestDistanceBFS.java
* Created: 2017-06-28
* Author: Sabbir Manandhar
*
* Copyright (c) 2017 Hogwarts.
*/
import java.util.LinkedList;
import java.util.Queue;
@leosabbir
leosabbir / HermanWorm.java
Created May 24, 2018 21:52
Searches for a destination cell from a source cell in a 3D matrix via shortest path
/* File: HermanWorm.java
* Created: 5/24/2018
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 Hogwart Inc.
*/
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
@leosabbir
leosabbir / CoinChange.java
Created May 24, 2018 22:09
Computes number ways we can represent the given amount with different combination of coin denominations
/* File: CoinChange.java
* Created: 2018-04-26
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 WorldLingo Inc.
*/
/**
* Number of ways given denominations can sum up a given total
*
@leosabbir
leosabbir / StockBenefit.java
Last active May 27, 2018 03:39
Compute maximum benefit possible by buying and selling an stock
/* File: StockBenefit.java
* Created: 2018-04-04
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 Hogwart Inc.
*/
/**
* Compute potential max profit
*
@leosabbir
leosabbir / PowerOfPowers.java
Last active May 27, 2018 03:33
Computes minimum number of multiplication required to compute the nth power of a number
/* File: PowerOfPowers.java
* Created: 2018-05-26
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 Hogwart Inc.
*/
import java.io.*;
import java.util.*;
@leosabbir
leosabbir / MaximumSquareSubMatrix.java
Last active June 3, 2018 06:23
Class to compute the maximum size of square sub matrix of given matrix
/* File: MaximumSquareSubMatrix.java
* Created: 2018-06-02
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 https://manandharsabbirk.appspot.com
*/
import java.util.Arrays;
/**
@leosabbir
leosabbir / MissingTwoNumbers.java
Last active June 8, 2018 16:59
Finds the two missing numbers in the given array which contains numbers from 1 to n inclusive except two numbers
/* File: MissingTwoNumbers.java
* Created: 6/6/2018
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 WorldLingo Inc.
*/
/**
* @author Sabbir Manandhar (lastname)(dot)(firstname)(at)gmail(dot)com
* @version 1.0