This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()){ |