Skip to content

Instantly share code, notes, and snippets.

View saldisobi's full-sized avatar

Sourabh Saldi saldisobi

  • Berlin
  • 03:31 (UTC -12:00)
View GitHub Profile
@saldisobi
saldisobi / StringKMP.kt
Last active September 25, 2019 16:53
KMP Algorithm : Kotlin Implementation
package strings
import java.util.*
class StringKMP {
fun matchPattern(pattern: String, text: String): Int {
var i = 0 //text pointer
package backToBasics;
import java.util.HashMap;
import java.util.Map;
public class MyTrie {
private TrieNode mRootTrieNode;
MyTrie() {
package backToBasics;
import java.util.LinkedList;
import java.util.Queue;
public class MyAvlTree {
private AvlNode mRootNode;
class BlankViewModel : ViewModel() {
fun testCoroutines() {
viewModelScope.launch(Dispatchers.IO) {
}
runBlocking {
launch {
package countdown.graphtheory;
import java.util.*;
public class Dijkstra {
static class Edge {
int from;
int to;
int weight;
interface CommandReceiver {
fun onAddClicked()
fun onTextUpdate(newText: String)
fun onDeleteClicked()
fun onListClicked()
fun onSaveClicked(text: String)
fun processCommand(command: Command) {
command.execute(this)
}
}
class MyModelViewModel @Inject constructor(
private val myModelRepository: MyModelRepository
) : ViewModel(), CommandReceiver {
override fun onAddClicked() {
viewModelScope.launch {
Log.v(TAG, "add command")
}
}
Icon(
modifier = Modifier.clickable { commandProcessor(AddCommand()) },
imageVector = Icons.Filled.Add,
contentDescription = "add"
)
Icon(
modifier = Modifier.clickable { commandProcessor(TextUpdateCommand(nameMyModel)) },
imageVector = Icons.Filled.Edit,
contentDescription = "edit"
class Solution {
fun networkDelayTime(times: Array<IntArray>, n: Int, k: Int): Int {
val graph = HashMap<Int, LinkedList<IntArray>>()
// step 1 iterate over given times list & create an adjancy list graph representation
times.forEach{node->
val src: Int = node[0]
val target : Int = node[1]
val weight : Int = node[2]
fun findTheCity(n: Int, edges: Array<IntArray>, distanceThreshold: Int): Int {
val graphArr = Array(n){
IntArray(n)
}
for (i in 0 until n) {
Arrays.fill(graphArr[i], Int.MAX_VALUE)
graphArr[i][i] = 0