Category Archives: Design Pattern

Multiplication using Bitwise Operator

package leetcode; /** * Multiply using Bitwise Operator * @author asharda * */ public class MultiplicationUsingBit { public int multiply(int a,int b) { int res=0; while(b>0) { if((b&1) !=0) { res=res+a; } a=a<<1; b=b>>1; } return res; } /** * … Continue reading

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

Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0

/** * @author asharda * */ public class Matrix { public int [][] resetMatrix(int [][]a) { int row[]=new int [a.length]; int []column=new int[a[0].length]; for(int i=0;i<a.length;i++) { for(int j=0;j<a[0].length;j++) { if(a[i][j]==0) { row[i]=1; column[j]=1; }//end of if }//end of j }//end … Continue reading

Posted in Data Structures, Design Pattern, 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

Implement strStr()

https://leetcode.com/problems/implement-strstr/description/ public class Solution { public int strStr(String haystack, String needle) { if(haystack.contains(needle)) { return haystack.indexOf(needle); } else { return -1; } } public static void main(String[] args) { Solution h=new Solution(); System.out.println(h.strStr(“hello”, “ll”)); } }

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

Strategy Design Pattern -Java

package test; /** * Basic Interface * @author asharda * */ interface StratgeyIn { void doOperation(int num1, int num2); }   /** * Implement OperationAdd * * @author asharda * */ class OpeartionAdd implements StratgeyIn { @Override public void doOperation(int … Continue reading

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

Simple class in Python

”’ Created on Dec 30, 2016 @author: asharda ”’ class Class: studentcount=0 def __init__(self,name,salary): self.name=name self.salary=salary Class.studentcount+=1 def displayCount(self): print(“Count seen is “,self.studentcount) c1=Class(“Ashish”,100000) c2=Class(“Ajay”,2000) c2.displayCount()

Posted in Design Pattern, Python, Uncategorized | Leave a comment

Singleton Design Pattern Java

package tests; import org.testng.annotations.Test; class Singleton { private static Singleton object=new Singleton(); private Singleton() { } public static Singleton getInstance() { return object; } public void showMessage() { System.out.println(“This is singleton class”); } } public class SingletonTest { @Test public … Continue reading

Posted in Design Pattern, Java | Leave a comment