Instantly share code, notes, and snippets.

// If Array was already sorted
// Complexity - O(n)
private int[] findPair_4(int[] A) {
int left = 0, right = A.length - 1;
while (left < right) {
int s = A[left] + A[right];
if (s == 0)
return new int[]{A[left], A[right]};
else if (s > 0)

Keybase proof

I hereby claim:

  • I am ST0LE on github.
  • I am gauravkamath ( on keybase.
  • I have a public key whose fingerprint is AC20 EC1E 4274 DA5F 32E4 4704 B9C9 97B3 05BE A391

To claim this, I am signing this object:

View Find-FirstItem.ps1
Function Find-FirstItem {
[Parameter(Mandatory, Position = 0)]
[string] $Filter
Get-ChildItem -Recurse -Filter $Filter | Select-Object -First 1 -ExpandProperty FullName
// Complexity - O(n^2), Space Complexity - O(n^2)
private int[] findTriple_3(int[] A) {
Map<Integer, int[]> map = new HashMap<Integer, int[]>();
for (int i = 0, l = A.length; i < l; i++) {
for (int j = i + 1; j < l; j++) {
if (map.containsKey(A[j])) {
int[] pair = map.get(A[j]);
return new int[]{pair[0], pair[1], A[j]};
View Systray.cs
using System;
using System.Drawing;
using System.Windows.Forms;
namespace MyTrayApp
public class SysTrayApp : Form
public static void Main()
// Complexity - O(n^2 logn)
private int[] findTriple_2(int[] A) {
Arrays.sort(A); // O(nlogn)
for (int i = 0, l = A.length; i < l && A[i] < 0; i++) { //O(n^2 logn)
for (int j = i + 1; j < l && A[i] + A[j] < 0; j++) {
int k = Arrays.binarySearch(A, j + 1, l, -A[i] - A[j]);
if (k > j) return new int[]{A[i], A[j], A[k]};
return null;
View MediaKeys.ahk
; ^ = Ctrl
; volume up
; volume down
; volume mute
View autoexec.cfg
alias +jumpthrow "+jump;-attack"
alias -jumpthrow "-jump"
bind mouse3 +jumpthrow
bind mouse5 +voicerecord
alias +fwdjumpthrow "+forward;+jump;-attack"
alias -fwdjumpthrow "-forward;-jump"
bind capslock +fwdjumpthrow
exec buyscript;
alias +djump "+jump; +duck"
alias -djump "-jump; -duck"
from collections import Counter
from heapq import heapify, heappop, heappush
s = input()
c = Counter(s)
pq = [(c[k], k, None, None) for k in c]
codes = {}
while len(pq) > 1:
r = heappop(pq)

Distributed Circular linked list sum

You are given a circular linked list whose nodes are distributed. Every node has next pointer and a method send(integer). A node can talk to its next node only. Different instances of same �threads are running in the nodes. How would you implement the run method of the thread class so that each node prints the sum of complete linked list.

Distributed binary tree sum

You are given a binary tree where each node has an integer value, a left, right and parent pointer. Every node is an independent distributed system where a thread is running in each node. You can talk to other node only by one method called "send(node, data)". And a node can call "send" only to its children or parent. How will you design the system so that all the nodes know the total sum of values of all the nodes in the binary tree and report them asynchronously.

Distributed doubly linked list sum

You are given a doubly linked list whose nodes are distributed. Every node has n