This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class Concordance { | |
static class Word{ | |
String text; | |
int count; | |
public Word(String text, int count ){ | |
this.text = text; | |
this.count = count; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Palindrome2 { | |
public static boolean isPalindrome(String input){ | |
if (input==null) | |
return false; | |
if(input.trim()==""){ | |
return true; | |
} | |
int i = 0; | |
int j = input.length()-1; | |
// "Race car!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
public class VersionControlMapSystem { | |
private static Integer currentVersion = null; | |
private static VersionControlMapSystem versionControlMapSystem; | |
private Map<Integer, Map<String, String>> controlMap = new HashMap<>(); | |
private VersionControlMapSystem(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CalculateModOfPow { | |
public static void calculateModOfPow(int x, int y, int z){ | |
int result = calculate(x, y, z); | |
System.out.println("("+x+" ^ "+y+") % "+z+" = "+result); | |
} | |
public static int calculate(int n, int y, int z){ | |
if(y==0) | |
return 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class CountPairsWithEvenSum { | |
public static void countPairs(int [] input){ | |
System.out.println("Given Input: " + Arrays.toString(input)); | |
int evenCount=0; | |
int oddCount=0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
public class PrintTwoEqualArray { | |
public boolean partition(int [] input){ | |
System.out.println("Given array: " + Arrays.toString(input)); | |
int sum = 0; | |
for (int i = 0; i <input.length ; i++) { | |
sum +=input[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QuickSort { | |
private int[] arrA; | |
public QuickSort(int[] arrA) { | |
this.arrA = arrA; | |
} | |
public void quickS(int low, int high) { | |
int mid = (low + high) / 2; | |
int left = low; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WellFormedParentheses { | |
public Boolean isWellFormed(String strParentheses) { | |
if (strParentheses == null) { | |
return false; | |
} | |
// Idea is to have two counters, one for open parentheses '{' and one | |
// for close '}' | |
// Read one character at a time and increment one of the counters | |
// If any given point of time count of close parentheses is greater than |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Here objective is find an element in two dimensional array | |
//all rows and columns of an array are sorted in ascending order respectively | |
public class FindElementInSorted2DArray { | |
public Boolean findElement(int[][] arrA, int number) { | |
// start from the left top corner, say ele; | |
// if ele>number -> move left | |
// if ele<number -> move right | |
// if you cant move further to find the number , return false | |
int row = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package interviewQuestion; | |
//Use recursive approach | |
//Compare first and last characters if they are not same- return false | |
//If they are same make, remove the first and last characters and make a recursive call. | |
public class Palindrome { | |
public Boolean isPalindrome(String strX) { | |
if (strX.length() < 2) | |
return true; |
NewerOlder