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 / LinkedList.kt
Created January 6, 2020 20:26
Linked List in kotlin
View LinkedList.kt
import java.lang.StringBuilder
fun main() { //testing Linked List
var linkedList = LinkedList()
dicarlomagnus / MaximumSumSubarrayOfSizeK.kt
Created January 6, 2020 20:23
Maximum Sum Subarray of Size K
View MaximumSumSubarrayOfSizeK.kt
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 / SmallestSubarrayWithAGivenSum.kt
Created January 6, 2020 20:22
Smallest Subarray with a given sum, in kotlin
View SmallestSubarrayWithAGivenSum.kt
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 / Trie.kt
Created December 30, 2019 01:31
Trie in kotlin, Insert, find and fetch
View Trie.kt
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()){