Skip to content

Instantly share code, notes, and snippets.

View OverrideArraysSort.java
import java.util.Arrays;
import java.util.Comparator;
public class OverrideArraysSort {
static int temp = 0;
static class Employee{
int id;
String name;
int salary;
View MinimumTimeDifference.java
import java.util.*;
public class MinimumTimeDifference {
public int findMinDifference(List<String> timePoints) {
System.out.println("Given hours: " + Arrays.toString(timePoints.toArray()));
int minimum = Integer.MAX_VALUE;
List<Integer> minutesList = getMins(timePoints);
Collections.sort(minutesList);
View FindDepartureAndDestination.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class FindDepartureAndDestination {
public static void find(List<List<String>> passes) {
Map<String, Integer> map = new HashMap<>();
for(int i=0;i<passes.size();i++){
View ArithmeticProgressionNthTerm.java
public class ArithmeticProgressionNthTerm {
public static void printAPNthTerm(int a, int d, int n){
System.out.println("a = " + a +", d = " + d + ", n = " + n);
int term = a + (n-1)*d;
System.out.println(n + "th term: " + term);
}
public static void main(String[] args) {
printAPNthTerm(1, 2, 5);
View ArithmeticProgressionSeries.java
public class ArithmeticProgressionSeries {
public static void printAP(int a, int d, int n){
System.out.println("a = " + a +", d = " + d + ", n = " + n);
for (int i = 1; i <=n ; i++) {
int term = a + (i-1)*d;
System.out.print(term + " ");
}
System.out.println();
}
View isArithmeticProgression.java
import java.util.Arrays;
public class isArithmeticProgression {
public static boolean checkArithmeticProgression(int[] arr) {
Arrays.sort(arr);
Integer d = null;
int prev = arr[0];
for(int i=1;i<arr.length;i++){
if(d==null){
View NonDecreasingArray.java
public class NonDecreasingArray {
public static boolean check(int[] input) {
int countR = 0;
int len = input.length;
int prev = input[len-1];
for(int i=len-2;i>=0;i--){
if(prev<input[i]){
countR++;
}else
prev = input[i];
View CountLargestGroups.java
import java.util.HashMap;
import java.util.Map;
public class CountLargestGroups {
public static int countLargestGroup(int n) {
Map<Integer, Integer> map =new HashMap<>();
int largestGrpSize = 0;
for(int i=n;i>0;i--){
int num = i;
View ExtraElementInTwoArrays.java
import java.util.Arrays;
public class ExtraElementInTwoArrays {
public static void getExtraElement(int [] arrA, int [] arrB){
int extraElement = 0;
for (int i = 0; i <arrA.length ; i++)
extraElement ^= arrA[i];
View ThreeConsecutivesOdds.java
import java.util.Arrays;
public class ThreeConsecutivesOdds {
public static boolean check(int[] input) {
int count = 0;
for(int i=0;i<input.length;i++){
if(input[i]%2!=0)
count++;
else