Skip to content

Instantly share code, notes, and snippets.

View swapnala's full-sized avatar

Swapnal Acharya swapnala

View GitHub Profile
@swapnala
swapnala / MinMovesSolution.java
Created April 9, 2017 04:37
There are N objects kept in a row. The ith object is at position x_i. You want to partition them into K groups. You want to move all objects belonging to the same group to the same position. Objects in two different groups may be placed at the same position. What is the minimum total amount by which you need to move the objects to accomplish thi…
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
import java.io.*;
import java.util.*;
class MinMovesSolution
{
public static void main(String [] args) throws Exception
{
Scanner sc = new Scanner(System.in);
String line = null;
@swapnala
swapnala / SumOfMinimumPathBST.java
Last active February 8, 2017 07:12
Find the minimum path sum for Binary Search Tree (From root to leaf)
public static int minPathSum(TreeNode root) {
if(root == null) return 0;
int sum = root.val;
int leftSum = Integer.MAX_VALUE;
int rightSum = Integer.MAX_VALUE;
if(root.right==null && root.left==null) {
return sum;
}else{
if(root.left!=null){