## Contains Duplicate II

Title: Contains Duplicate II Source: leetcode.com Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k. Java solution Java /* https://leetcode.com/problems/contains-duplicate-ii/ */ import java.util.HashMap; public class ...

## Contains Duplicate

Title: Contains Duplicate Source: leetcode.com Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct. Java solution Java /* https://leetcode.com/problems/contains-duplicate/ */ import java.util.HashSet; public class ContainsDuplicate { public ...

## Container With Most Water

Title: Container With Most Water Source: leetcode.com Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such ...

## Clone Graph

Title: Clone Graph Source: leetcode.com Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. Nodes are labeled uniquely. Java solution Java /* https://leetcode.com/problems/clone-graph/ */ import java.util.HashMap; import java.util.List; import java.util.ArrayList; public class CloneGraph { public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) { if(node==null) return null; HashMap<Integer, UndirectedGraphNode> visited = ...

## Running Hadoop Example(TDG/CH02) on Cloudera Quick Start VM1

prerequisite 1. VMWare Player (Oracle VM box didn’t work for me) Download VMWare Player 2. Cloudera Quick Start VM Download Cloudera Quick Start VM 3. Download CH02 example java code from here. 4. create a folder BigDataAssignment1/code(name it whatever you want) inside /home/cloudera/workspace/ 5. Download hadoop-core-0.20.2.jar from here and place it inside code folder you ...

## Find maximal uni-directional path length for a Binary Tree1

Continuing from our last post for a Generic Binary Tree implementation, we’ve come up with a solution to quite an interesting problem. We define a path in a binary tree to be a non-empty sequence of nodes that one can traverse by following the pointers in the nodes. A path only goes to the right ...

## Data truncation: Incorrect datetime value: ” for column2

While using Acitiviti API you might encounter this error which says something like this ### Error updating database. Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: ” for column ‘DEPLOY_TIME_’ at row 1### The error may involve org.activiti.engine.impl.persistence.entity.DeploymentEntity.insertDeployment-Inline### The error occurred while setting parameters### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: ” for column ‘DEPLOY_TIME_’ at row ...

## Add Two Integers without using Arithmetic Operators

Recently came across an interesting question of adding two numbers without using any of the arithmetic operators and thought of giving it a try. The first thought of solving the question was using bit-manipulation operations. The idea was to add the numbers bit-by-bit taking any carry forward (without actually adding them and instead using bit-wise ...

## To compare two folders (recursively) in Java13

Java package com.example; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.MessageDigest; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.Set; public class Compare { //This can be any folder locations which you want to compare File dir1 = new File("C:\\ComparisonFolder\\master"); File dir2 = new File("C:\\ComparisonFolder\\release"); public static void main(String ...args) { Compare compare = ...

## Count Triangles in a Graph1

The following code implementation counts the number of triangles present in a graph G. For graph representation JUNG API is used but can be extended/ changed to use any other notation by simple means. Java import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import edu.uci.ics.jung.graph.Graph; public class TriangleFinder { private Graph<Integer, String> g; /** * @return The ...