Skip to content

Instantly share code, notes, and snippets.

View dicarlomagnus's full-sized avatar

Carlos Hernandez Santes dicarlomagnus

  • Pangea Money Transfer
  • Mexico City
View GitHub Profile
@dicarlomagnus
dicarlomagnus / LinkedList.kt
Created January 6, 2020 20:26
Linked List in kotlin
import java.lang.StringBuilder
fun main() { //testing Linked List
var linkedList = LinkedList()
println(linkedList)
linkedList.preAppend(1).preAppend(2).preAppend(3)
println(linkedList)
linkedList.clear()
linkedList.append(1).append(2).append(3)
println(linkedList)
@dicarlomagnus
dicarlomagnus / MaximumSumSubarrayOfSizeK.kt
Created January 6, 2020 20:23
Maximum Sum Subarray of Size K
/*
Given an array of positive numbers and a positive number ‘k’, find the maximum sum of any contiguous subarray of size ‘k’.
Example 1:
Input: [2, 1, 5, 1, 3, 2], k=3
Output: 9
Explanation: Subarray with maximum sum is [5, 1, 3].
Example 2:
@dicarlomagnus
dicarlomagnus / SmallestSubarrayWithAGivenSum.kt
Created January 6, 2020 20:22
Smallest Subarray with a given sum, in kotlin
/*
Problem Statement #
Given an array of positive numbers and a positive number ‘S’, find the length of the smallest contiguous subarray whose sum is greater than or equal to ‘S’. Return 0, if no such subarray exists.
Example 1:
Input: [2, 1, 5, 2, 3, 2], S=7
Output: 2
Explanation: The smallest subarray with a sum great than or equal to '7' is [5, 2].
Example 2:
@dicarlomagnus
dicarlomagnus / Trie.kt
Created December 30, 2019 01:31
Trie in kotlin, Insert, find and fetch
fun main() {
var trie = Trie()
Trie.insert(trie, "hello", "hi", "hey", ""," *") //Inserting "hello", "hi", "hey" into the trie, "*" will be replace by empty string
println(Trie.find(trie, "hey")) //checking out if "hey exists inside the trie"
println(Trie.fetch(trie)) // traversing the trie and get all the words inside of it and printing them
}
class Trie(var node: MutableMap<Char, Trie> = mutableMapOf()){