Category Archives: Java

Divide Two Integers

https://leetcode.com/problems/divide-two-integers/description/ package src.test.java.examples;package src.test.java.examples; public class Dividend { public int divide(int dividend, int divisor) { int count = 0; boolean flag = false; if (dividend < 0 && divisor > 0) { flag = true; } else if (dividend > … Continue reading

Posted in Java, LeetCode Solutions, Uncategorized | Tagged | Leave a comment

Quick Sort

  /** * QuickSort using Java * @author asharda * */ public class QuickSort { public void qsort(int []arr,int left,int right) { // int left=0; // int right=arr.length-1; //System.out.println(“Lowest element is “+arr[left] + ” Highest element is “+arr[right]); int pivot=arr[right]; … Continue reading

Posted in Data Structures, Java, Uncategorized | Tagged | Leave a comment

Check if word exists in a string using Matcher

import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Using Patterns * * @author asharda * */ public class PatternTest { /** * @param args */ public static void main(String[] args) { String text = “This is the time of elections”; String search … Continue reading

Posted in Java, Uncategorized | Tagged , | Leave a comment

Knapsack Problem using Java

/** * Knapsack Problem to maximize value given the weight * @author asharda * */ public class Knapsack { public int maxValue(int []weight,int []value,int maxWeight) { int sum[]=new int [value.length]; sum[0]=value[0]; int max=value[0]; for(int i=1;i<value.length;i++) { if(weight[i-1]+weight[i]<=maxWeight) { sum[i]=Math.max(value[i], value[i-1]+value[i]); … Continue reading

Posted in Data Structures, Java, LeetCode Solutions, Uncategorized | Tagged , | Leave a comment

Find depth of binary tree

import java.util.Stack; /** * Find Depth of Binary Tree * @author asharda * */ class TreeNodes { int data; TreeNodes left; TreeNodes right; TreeNodes(int data) { this.data=data; } } public class TreeDepth { static int count=0; public void depth(Stack<TreeNodes> st) … Continue reading

Posted in Data Structures, Java, Java 8, Uncategorized | Tagged , | Leave a comment

Fibonnaic series using Java

  /** * Fibonnaci Series * @author asharda * */ public class Fibonnaci { public int getFib(int num) { if(num<2) { return num; } return getFib(num-1)+getFib(num-2); //return f; } public static void main(String[] args) { Fibonnaci f =new Fibonnaci(); System.out.println(“Fibonaci … Continue reading

Posted in Data Structures, Design Pattern, Java, Java 8, Uncategorized | Tagged , | Leave a comment

What is a Brute Force solution

Nice article on Brute Force : https://stackoverflow.com/questions/8103050/what-exactly-is-the-brute-force-algorithm?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Posted in Data Structures, Java, Uncategorized | Tagged | Leave a comment