Skip to content

Instantly share code, notes, and snippets.

View khekrn's full-sized avatar
🎯
Focusing

KK khekrn

🎯
Focusing
View GitHub Profile
@khekrn
khekrn / Coroutines.kt
Created August 30, 2021 05:38
Coroutines are lightweight
import kotlinx.coroutines.*
//Start
fun main() = runBlocking {
repeat(100_00_00){ // launches one million coroutines
launch{
delay(10000) // Wait for 10 Seconds
print(".")
}
}
@khekrn
khekrn / MagicSquare.java
Created September 11, 2020 11:58
Is Magic Square
public class MagicSquare {
// O(N + N*M) = O(N * M)
public boolean isMagicSquare(int[][] arr){
int diag1Sum = 0, diag2Sum = 0;
var rowSize = arr.length;
var colSize = arr[0].length;
for(int i = 0; i < rowSize; i++){
diag1Sum += arr[i][i];
@khekrn
khekrn / LongestSubStringWithKDistinctChar.java
Created September 11, 2020 11:52
find the length of the longest substring in it with no more than K distinct characters.
public class LongestSubStringWithKDistinctChar{
//O(N + K)
public int findLength(String str, int K) {
int windowStart = 0, maxLen = 0;
var dict = new HashMap<Character, Integer>();
for(int i = 0; i < str.length(); i++){
char rightChar = str.charAt(i);
dict.put(rightChar, dict.getOrDefault(rightChar, 0) + 1);
package com.firebase.samples;
import java.io.FileInputStream;
import java.util.concurrent.ExecutionException;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthException;
@khekrn
khekrn / filter.go
Created April 24, 2019 18:02
Simple bloom filter implementation in go
package filters
import (
"bytes"
"encoding/binary"
"errors"
"hash"
"math"
"math/rand"
@khekrn
khekrn / gist:8dbd5870563207c7fc1ccfdda2fb31a1
Created April 6, 2019 07:23 — forked from debasishg/gist:8172796
A collection of links for streaming algorithms and data structures
  1. General Background and Overview