Skip to content

Instantly share code, notes, and snippets.

View bangarharshit's full-sized avatar

Harshit Bangar bangarharshit

  • Twitter
View GitHub Profile
import UIKit
// Runnable -> no input, no output
// Callable -> no input -> Producer
// Function -> input, output
// Consumer
// **Higher order function**
import java.util.Arrays;
import java.util.List;
// Uber $ - 5 3 4 6 7 8 9 9 7 6 5 8
// Any day - You can buy 1 stock or you can sell all your stocks or do nothing.
// You have to maximize your profit.
// (9-5) + (9-3) + (9-4) + (9-6) + (9-7) + (8-7) + (8-6) + (8-5)
// 8, 5, 6, 7, 9, 9, 8
// max = 9
public class StockBuySell {
public class BalancedParanthesis2 {
public static void main(String[] args) {
}
// ((()))
private static boolean validExpression(String expression, int numOfRetriesAvailable) {
if (expression == null) {
return true;
}
public class Arbit {
public static void main(String[] args) {
Arbit arbit = new Arbit();
Container container = new Container();
container.a = 7;
container.b = 6;
arbit.change(container);
int d = 5;
arbit.changeInt(d);
System.out.println(container);
public class InsertionSort {
public int[] sort(int[] input) {
int[] output = new int[input.length];
for (int i=0; i<input.length; i++) {
int indexToInsert = 0;
for (int j=0; j<=i; j++) {
if (input[i] < output[j]) {
indexToInsert=j;
// Given a sorted linked list, delete all duplicates such that each element appear only once.
// For example,
// Given 1->1->2, return 1->2.
// Given 1->1->2->3->3, return 1->2->3.
/**
* Definition for singly-linked list.
* class ListNode {
* public int val;
// Given an array with n objects colored red, white or blue,
// sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
// Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
// Note: Using library sort function is not allowed.
// Example :
// Input : [0 1 2 0 1 2]
@bangarharshit
bangarharshit / EmailDummy.java
Created February 3, 2018 04:21
The current generated code (only the POJO part and removed adapter for brevity):
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class EmailDummy {
@Nonnull
public final String From;
@bangarharshit
bangarharshit / WeakReferenceCaller.java
Created December 22, 2017 11:01
Code to show that multiple calls to Weakreference.get() might return null.
// GC is a background thread and JVM doesn't have a spec for it to be daemon or not.
// https://stackoverflow.com/questions/5553783/java-garbage-collection-thread-priority
public class WeakReferenceCaller {
public static void main(String[] args) throws InterruptedException {
MyObject myObject = new MyObject();
Thread thread = new Thread(new WeakReferenceRunnable(myObject));
thread.start();
myObject = null;
System.out.println(myObject);
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.view.View;
import com.example.harshitbangar.ribswithoutdagger.ScreenStackImpl;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
public class CrossfadeTransition implements Transition {