Skip to content

Instantly share code, notes, and snippets.

@leosabbir
leosabbir / PairNumberByMultipleOfX.java
Last active April 13, 2018 23:55
Linear Time solution to determine if all the numbers pair up
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/**
* http://initcodes.blogspot.com/2018/04/number-pairs-whose-sum-is-multiple-of.html
*
* Kelly gives Ashley N chocolates each having a price pi, (where pi is the price of ith chocolate),
@leosabbir
leosabbir / NumberOfSubsetsWithTargetSum.java
Last active April 14, 2018 16:15
Computes number of sub sets that sum to targetSum
/* File: NumberOfSubsetsWithTargetSum.java
* Created: 2018-04-13
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 manandharsabbirk.appspot.com
*/
package subsets;
import java.util.HashMap;
@leosabbir
leosabbir / Fibonacci.java
Created April 14, 2018 18:13
Different methods to compute nth Fibonacci number
/* File: NumberOfSubsetsWithTargetSum.java
* Created: 2017-04-13
* Author: Sabbir Manandhar
*
* Copyright (c) 2017 manandharsabbirk.appspot.com
*/
/**
* Computes Number of Sub-sets that have sums to targetSUm
*
@leosabbir
leosabbir / java.file-template
Created April 16, 2018 01:23
template setting file for sublime
<template>
<!-- Or you set a path to a seperate Template File here -->
<file>java.java</file>
<!-- The filename for the new File, you can use the arguments to make it dynamic -->
<filename>$name.java</filename>
<!-- Optional: Add as much arguments as you need, they will be asked in the order specified -->
<arguments>
<name>Name (without extension):</name>
@leosabbir
leosabbir / java.java
Created April 16, 2018 01:31
template file for file type java for sublime
/* File: $name.java
* Created: $date2
* Author: $author
*
* Copyright (c) $year https://manandharsabbirk.appspot.com
*/
import java.io.*;
import java.util.*;
@leosabbir
leosabbir / FileTemplates.sublime-settings
Created April 16, 2018 01:38
Sublime Setttings file for FileTemplates
{
"excluded_dir_patterns": [
"tmp", "|.git", "|.svn"
],
"attrs": {
"author": "Sabbir Manandhar",
"company": "Hogwart",
"email": "manandhar.sabbir@gmail.com",
"github": "github.com/leosabbir"
},
@leosabbir
leosabbir / BinarySearch.java
Last active April 21, 2018 17:47
Binary Search with Limit and Bound Search
/* File: BinarySearch.java
* Created: 2017-10-25
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 WorldLingo Inc.
*/
import java.util.List;
import java.util.ArrayList;
@leosabbir
leosabbir / ConvertToBinary.java
Last active April 27, 2018 23:06
Conversion of a decimal number into equivalent binary representation
/**
* Converts given Decimal number into Binary representation
* @param m decimal number to converto to binary
* @return Binary representation of input decimal number
*/
public String convert(int m) {
String binary = "";
while(m > 0) {
binary = (m % 2) + binary; // append new remainder at the beginning
m /= 2;
@leosabbir
leosabbir / StaticMethodsTest.java
Last active May 3, 2018 17:28
Test class to Test a class with Multiple Static Methods using PowerMockito
/* File: StaticMethodsTest.java
* Created: 2018-05-03
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 Hogwarts.
*/
package com.worldlingo;
import junit.framework.Assert;
@leosabbir
leosabbir / DetectLoopInLinkedList.java
Last active May 11, 2018 05:56
Detecting Loop in a Linked List and Identify the Start of the Loop
/* File: DetectLoopInLinkedList.java
* Created: 2018-05-09
* Author: Sabbir Manandhar
*
* Copyright (c) 2018 Hogwart
*/
import java.util.HashSet;
import java.util.Set;