Implementing Stack and Queue in JavaScript

In JavaScript, both stack and queue data structures are commonly implemented using arrays. Here’s a brief conclusion on how to implement these structures, excluding priority queues which are slightly more complex and typically use third-party libraries. Stack Stacks follow the LIFO principle. Using JavaScript arrays, we can mimic this behavior easily. create a stack 1 const stack = []; push to the top of stack

Leetcode 198.House Robber

Here are two approaches to solving the classic “House Robber” problem: Recursion + Backtracking, and Iteration. Both methods apply dynamic programming effectively, albeit in different ways. Solution One (Recursion + Backtracking) This solution I found online (author: labuladong) uses recursion and backtracking. I am not sure if this counts as dynamic programming. Basic Idea Standing in front of the i-th house, the robber has two options: rob it and jump

Top K Frequent Elements and Heapq in Python

Heapq in Python This module provides an implementation of the heap queue algorithm, also known as the priority queue algorithm. Heaps are binary trees for which every parent node has a value less than or equal to any of its children. This implementation uses arrays for which heap[k] <= heap[2*k+1] and heap[k] <= heap[2*k+2] for all k, counting elements from zero. For the sake of comparison, non-existing elements are considered

Fundamentals of Git

Explore some essential aspects of the version control tool Git. Concept Initially, as a newcomer, I confused Git with GitHub (a platform), not realizing Git is fundamentally a local tool. Some refer to it as a version control tool, a file system, or even a database with key-value pairs. To harness its capabilities, it’s crucial to understand the primary command: 1 git init This command creates a .git folder in

Functions in Kotlin

In this post, I aim to summarize the essential aspects of function syntax in Kotlin. While this post touches upon some commonly used functionalities, especially in Android development, it doesn’t delve deep into the advanced usages. Regular Functions Regular functions are the basic building blocks. Here’s a simple function that compares the lengths of two strings: 1 2 3 fun compare(a: String, b: String): Boolean { return a.length < b.length