Skip to content

Instantly share code, notes, and snippets.

View anandabhishek73's full-sized avatar

Abhishek Anand anandabhishek73

View GitHub Profile
@anandabhishek73
anandabhishek73 / DelayQueue
Created August 18, 2021 07:51
Java Multi Producer Multi Consumer, Thread Safe, Blocking Delayed Queue
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
@anandabhishek73
anandabhishek73 / NextGreatestElement.java
Created November 1, 2017 18:57
NEXT GREATEST ELEMENT: For each element of input array, it finds the next bigger-than-itself element in that array; -1 if no greater element is present.
import java.util.Arrays;
import java.util.Stack;
/**
* Created by Abhishek Anand on 24-Oct-17.
*/
/*
Finds the next greatest element for each element in an array. -1 if no greater element is present.
*/
@anandabhishek73
anandabhishek73 / RomanNumeral.java
Last active November 1, 2017 20:00
Java utility to convert Roman and Decimal numbers to each other. Also has a utility function to check validity of a Roman numeral. Includes positive and negative use-cases
import java.util.HashMap;
import java.util.TreeMap;
/**
* Created by Abhishek Anand on 01-Nov-17.
*/
public class RomanNumeral {
private static final int D2R_METHOD_FLAG = 2;
@anandabhishek73
anandabhishek73 / LowestNumberRemovingNdigits.java
Last active October 31, 2017 21:17
Build Lowest Number by Removing n digits from a given number. Given a string ‘str’ of digits and an integer ‘n’, build the lowest possible number by removing ‘n’ digits from the string and not changing the order of input digits. The idea is to remove local-maxima, scanning left->right, in initial K - N digits (K=total digits); such that the sequ…
import java.util.LinkedList;
import java.util.ListIterator;
/**
* Created by Abhishek on 31-Oct-17.
* <p>
* http://www.geeksforgeeks.org/build-lowest-number-by-removing-n-digits-from-a-given-number/
* <p>
* Build Lowest Number by Removing n digits from a given number
* 4
@anandabhishek73
anandabhishek73 / PlusPattern.java
Last active October 25, 2017 13:09
Finds the size of largest ‘+’ formed by a particular element(here called 'symbol') in a 2D matrix of any size.
public class PlusPattern {
/**
* Utility method to verify matrix dimensions
*
* @param a matrix to be verified
* @return true if matrix size is greater than 0;
*/
private static boolean isValid(int[][] a) {
return a.length > 0 && a[0].length > 0;