https://leetcode.com/problems/merge-k-sorted-lists/description/ You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.Merge all the linked-lists into one sorted linked-list and return it.Example 1:Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] Explanation: The linked-lists are: [ 1->4->5, 1->3->4, 2->6 ] merging them into one sorted list: 1->1->2->3->4->4->5->6Example 2:Input: lists = [] Output: []Example…
Read moreTesting by mocking Injected Component with Dagger 2 in Android development.
A key strength of Dependency Injection is that unit testing with DI supposed to be easy by switching components with their mock representatives. To be able to successfully mock a dependency is not hard, but it still required a few steps that may take a couple hours to get right. Below is a tutorial on…
Read moreAlternative colored path BFS in Kotlin
https://leetcode.com/problems/shortest-path-with-alternating-colors/ fun shortestAlternatingPaths(n: Int, red_edges: Array<IntArray>, blue_edges: Array<IntArray>): IntArray { val answer : Array<IntArray> = Array(2){IntArray(n)} val finalAnswer = IntArray(n) for (i in 1 until n) { answer[0][i] = 2*n answer[1][i] = 2*n } val queue: Queue<Int> = ArrayDeque() queue.offer(0) while (!queue.isEmpty()) { val current = queue.remove() for (edge in red_edges) { if (edge[0] ==…
Read more720. Longest Word in Dictionary – Using modified Trie
https://leetcode.com/problems/longest-word-in-dictionary/ In this problem, we build a Trie, and then we traverse it and try to get the leaf with the longest word. A simple twist is that, at every node, we only traverse further to a child if and only if the child is a word node, meaning it corresponds to a word existed…
Read moreHouse Robber II – How to rob houses efficiently.
https://leetcode.com/problems/house-robber-ii/ We are not actually talking about robbing real house here. The problem is: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one….
Read moreContiguous-array Problem
A short, fun, and potentially challenging coding problem that I “randomed” on Leetcodehttps://leetcode.com/problems/contiguous-array/Given a binary array, find the maximum length of a contiguous subarray with an equal number of 0 and 1.Example 1:Input: [0,1] Output: 2 Explanation: [0, 1] is the longest contiguous subarray with equal number of 0 and 1.Example 2:Input: [0,1,0] Output: 2…
Read more