[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/faraimtb/java-algorithims/main/Main.java [Back]  [Original]

package com.ematrix;


import java.util.Arrays;
import java.util.Iterator;

public class Main {


    }
    /* This code is contributed by Rajat Mishra */


//    int mIndex=lIndex+rIndex-lIndex/2;
//        while(lIndexsrcIndex)
//                return binarySearch(ary,lIndex,mIndex-1,srcIndex);
//
//                return binarySearch(ary,mIndex+1,lIndex,srcIndex);
//                }
//
//                return -1;
//    int numStr = str.length();
//    int numPtn = ptn.length();
//    int i = 0;
//    int j = 0;
//    int count;
//    int startIndex = 0;
//    int endIndex = 0;
//    int minLength = numStr;
//    boolean found = false;
//    HashMap mpPtn = new HashMap();
//
//            if (str.isEmpty() || ptn.isEmpty()) {
//
//                    return "";
//                    }
//
//                    for (int x = 0; x < numPtn; x++) {
//        char c = ptn.charAt(x);
//
//        mpPtn.put(c, mpPtn.getOrDefault(c, 0) + 1);
//
//        }
//
//        count = mpPtn.size();
//
//        while (j < numStr) {
//        char endChar = str.charAt(j++);
//        if (mpPtn.containsKey(endChar)) {
//        mpPtn.put(endChar, mpPtn.get(endChar) - 1);
//        if (mpPtn.get(endChar) == 0) count-=1;
//        }
//
//        if (count > 0) continue;
//
//        while (count == 0) {
//        char startChar = str.charAt(i++);
//        if (mpPtn.containsKey(startChar)) {
//        mpPtn.put(startChar, mpPtn.get(startChar) + 1);
//        if (mpPtn.get(startChar) > 0) count+=1;
//        }
//        }
//
//        if ((j - i) < minLength) {
//        startIndex = i;
//        endIndex = j;
//        minLength = (j - i);
//        found = true;
//        }
//
//
//        }
//
//        if (found) {
//        return str.substring(startIndex-1, endIndex);
//        } else {
//        return "";
//        }


// write your code here
//System.out.println(solution(1000));
//        var fibNums = new ArrayList();
//        int prevFib=1,currentFib=2,n=0;
//        int totalValue=0,evenTotal=0;
//        fibNums.add(prevFib);
//        fibNums.add(currentFib);
//        totalValue=(prevFib+currentFib);
//        while(totalValue>2);
//
//        final int TIMES_TO_FLIP = 20;
//        int heads = 0;
//        int tails = 0;
//        // Create a Random object
//        Random random = new Random();
//        for (int i = 0; i < TIMES_TO_FLIP; i++) {
//            // 0 or 1
//            int result = random.nextInt(2);
//
//            if (result == 1) {
//
//                heads++;
//            } else {
//
//                tails++;
//            }
//        }
//        System.out.println("There were "
//                + heads
//                + " heads and "
//                + tails
//                + " tails");

//        String txt = "Please locate where 'locate' occurs!";
//        System.out.println(factorial(5)); // Outputs 7
//
//        ArrayList cars = new ArrayList();
//        cars.add("Volvo");
//        cars.add("BMW");
//        cars.add("Ford");
//        cars.add("Mazda");
//        Collections.sort(cars);
//        for (String car:cars) {
//            System.out.println(car);
//        }

//        HashMap capitalCities = new HashMap();
//
//        // Add keys and values (Country, City)
//        capitalCities.put("England", "London");
//        capitalCities.put("Germany", "Berlin");
//        capitalCities.put("Norway", "Oslo");
//        capitalCities.put("USA", "Washington DC");
//        System.out.println(capitalCities);


//

//        ArrayList cars = new ArrayList();
//        cars.add("Volvo");
//        cars.add("BMW");
//        cars.add("Ford");
//        cars.add("Mazda");
//
//        // Get the iterator
//        Iterator it = cars.iterator();
//
//        // Print the first item
//        System.out.println(it.next());
//
//        while(it.hasNext()) {
//            System.out.println(it.next());
//        }

//        Pattern pattern = Pattern.compile("w3schools", Pattern.CASE_INSENSITIVE);
//        Matcher matcher = pattern.matcher("Visit W3Schools!");
//        boolean matchFound = matcher.find();
//        if(matchFound) {
//            System.out.println("Match found");
//        } else {
//            System.out.println("Match not found");
//        }
//
//        ArrayList numbers = new ArrayList();
//        numbers.add(5);
//        numbers.add(9);
//        numbers.add(8);
//        numbers.add(1);
//        numbers.forEach( (n) -> { System.out.println(n); } );


//    int[] aryThree= new int[n+m];
//    int i=0;
//    int j=0;
//    int k=0;
//
//        while(i

Web Proxy Viewer  |  New URL  |  Original Page