Leetcode

1146. Snapshot Array

https://leetcode.com/problems/snapshot-array/description/ Here’s a breakdown of the code: The class SnapshotArray has a member variable snap which is a HashMap. This HashMap has an Integer key (representing the index) and a nested HashMap as its value. The nested HashMap has an Integer key (representing the snapshot ID) and an Integer value (representing the value at that…

Leetcode

746. Min Cost Climbing Stairs

You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the step with index 0, or the step with index 1. Return the minimum cost to reach the top of the floor. Example 2: Solution: DP https://leetcode.com/problems/min-cost-climbing-stairs/description/?envType=study-plan-v2&id=dynamic-programming

Leetcode

1137. N-th Tribonacci Number

The Tribonacci sequence Tn is defined as follows:  T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given n, return the value of Tn. https://leetcode.com/problems/n-th-tribonacci-number/description/?envType=study-plan-v2&id=dynamic-programming

Tech

Running API in loop using Postman Runner

Postman is a popular API development tool that allows developers to design, test, and document APIs with ease. It provides a user-friendly interface that enables developers to make requests to APIs, examine responses, and debug issues. With Postman, developers can easily create requests, add headers, and manage complex authentication protocols. Postman also provides powerful testing…

ruby

Drawbacks of Active Record

Active Record is a pattern used in software engineering that represents the database in an object-oriented manner. In other words, it’s a way to use objects to interact with a database instead of writing SQL queries directly. In Ruby on Rails, Active Record is the default ORM (Object-Relational Mapping) that allows developers to define database…

Tech

TIL – Native modifier in Java

While going through multithreading in java you must have came across this function “Thread.yield This function is special for me because the definition of the function is So let’s go in detail about the native modifier In Java, the native modifier is used to indicate that a method is implemented in a platform-specific manner, typically…

ruby

Ruby on Rails object lifecycle and callbacks

In ROR, the lifecycle of an object is attached to the database of the application. Objects are created in memory first then later stored in the database. An object have following lifecycle Creation Validation Save Update Deletion These lifecycle have callbacks attached to each of them by which we can inject our custom logic. Creation…

Tech

How to make a class Immutable in java

Making a class immutable means that its state cannot be changed once it’s created. In other words, all the fields of the class are set at the time of instantiation and cannot be modified afterward. This can be achieved by using the following techniques: Declaring all fields as final: This ensures that the fields cannot…

Pages