Skip to content

Instantly share code, notes, and snippets.

import java.util.Arrays;
public class BinarySearch {
private int num[] ;
private int len ;
public void searchElement(int[] num,int x) {
this.len= num.length;
-
public static void lsearch() {
Integer[] inputArray = {2,3,31,24,5,6,61,7,8,92};
Integer num = 61;
Stream.of(inputArray).forEach(x->{
if(x==num){
System.out.println("Number foound at location : "+x);
}
});
package facebook.tvidushi.arrays;
import java.util.*;
import java.io.*;
public class SortSquares
{
public static void sortSquares(int arr[])
{
package facebook.tvidushi.numbers;
import java.util.Arrays;
public class RearrangeElements {
/*
Gives an array of unsorted int (may have negative number),
rearrange the array such that the
num at the odd index is greater than the num at the even index.
package facebook.tvidushi.numbers;
import java.util.HashSet;
public class FilterNine {
/**
Remove any number containing 9 like 9, 19, 29, ... 91, 92, ... 99, 109...
package com.tvidushi1.arrays;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Powerset {
public static void main(String[] args) {
List <Object> list = new ArrayList<Object>();
package com.tvidushi;
public class Squareroot {
/*
Steps:
Use binary search to find the square root.
1. Initialize, start = 0, end = number, mid = (start+end)/2.
2. Set prevMid = 0, as the previous mid value.
3. Find diff = absolute difference between prevMid and mid.
package facebook.numbers;
import java.util.HashMap;
public class CheckSquare {
//Determine whether a number is the sum of two squares, such as 17 = 16 +1
public static void main(String args[]) {
checkSquare( 100);
package com.tvidushi;
public class Squareroot {
/*
Steps:
Use binary search to find the square root.
1. Initialize, start = 0, end = number, mid = (start+end)/2.
2. Set prevMid = 0, as the previous mid value.
3. Find diff = absolute difference between prevMid and mid.
**
*
*/
package com.tvidushi.hashmap;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**