This file contains hidden or 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 BinarySearch { | |
| private int num[] ; | |
| private int len ; | |
| public void searchElement(int[] num,int x) { | |
| this.len= num.length; |
This file contains hidden or 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 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); | |
| } | |
| }); |
This file contains hidden or 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 facebook.tvidushi.arrays; | |
| import java.util.*; | |
| import java.io.*; | |
| public class SortSquares | |
| { | |
| public static void sortSquares(int arr[]) | |
| { |
This file contains hidden or 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 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. |
This file contains hidden or 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 facebook.tvidushi.numbers; | |
| import java.util.HashSet; | |
| public class FilterNine { | |
| /** | |
| Remove any number containing 9 like 9, 19, 29, ... 91, 92, ... 99, 109... |
This file contains hidden or 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 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>(); |
This file contains hidden or 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 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. |
This file contains hidden or 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 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); |
This file contains hidden or 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 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. |
This file contains hidden or 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 com.tvidushi.hashmap; | |
| import org.junit.After; | |
| import org.junit.Before; | |
| import org.junit.Test; | |
| /** |