BLOGS IN DSA
The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually are at most t. You can swim infinite distances in zero time ...
Sumit Kumar
Suppose you are at a party with n people (labeled from 0 to n - 1) and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know him/her but he/she does not know any of them. There will be exactly one celebrity if he/she is in the party ...
Sumit Kumar
Alice and Bob are opponents in an archery competition. Alice first shoots numArrows arrows and then Bob shoots numArrows arrows. Return the array bobArrows which represents the number of arrows Bob shot on each scoring section from 0 to 11. The sum of the values in bobArrows should equal numArrows ...
Sumit Kumar
A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. Construct a deep copy of the list . The deep copy should consist of exactly n brand new nodes. This solution use no extra space ...
Sumit Kumar
Given a string s where s consists of lowercase English letters, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results . We will solve this problem in linear runtime and with constant space ...
Sumit Kumar
UN Spy satellite Watchtower-14 has detected martian stealth ballistic missile platforms. Earth has decided to launch a pre-emptive strike to destroy those platforms and eliminate the MCR's first strike capability. The only defence against these beasts is our planetary railgun. Our Railgun once fully charged, can eliminate a single planet buster. However, our railgun takes one minute to charge for firing ...
Sumit Kumar
Given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries that you can collect from the (i, j) cell.You have two robots that can collect cherries for you ...
Sumit Kumar
Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you can reach to any index with value 0. Notice that you can not jump outside of the array at any time. We will solve this problem using BFS ...
Sumit Kumar
You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order...
Sumit Kumar
A disjoint-set data structure is a data structure that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets...
Sumit Kumar
There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches the island's right and bottom edges...
Sumit Kumar
You are given an n x n integer matrix board where the cells are labeled from 1 to n^2 in a Boustrophedon style starting from the bottom left of the board (i.e. board[n - 1][0]) and alternating direction each row....
Sumit Kumar
On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed....
Sumit Kumar
The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other...
Sumit Kumar
Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature....
Sumit Kumar
There are a row of n houses, each house can be painted with one of the three colors-- red, blue or green. The cost of painting each house with a certain color is different....
Sumit Kumar
Super Egg Drop problem is decribed in the Wikipedia's article for Dynamic Programming.Lets look at how we solve this problem using memoization and binary search .The code for this is written in JavaScript ...
Sumit Kumar
The primary challenge in this problem is determining an efficient way to find the number of valid words for each puzzle. To achieve this, we need to somehow put the words into a data structure that allows us to perform a quick search ...
Sumit Kumar
Aggressive Cows is based on the concept, Binary Search . In this question we have to maximize the minimum gap between two aggressive cows. The code for this is written in JavaScript ...
Sumit Kumar
We are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. We are asked to burst all the balloons....
Sumit Kumar
Making A Large Island is a spin off of popular Number of Island problem . In this problem we would be using DFS. The code for this is written in JavaScript ...
Sumit Kumar
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root...
Sumit Kumar
Trapping Rainwater is one of my favorite question in DSA . In this post , I will be covering the steps required to reach the optimal solution . The code for this is written in JavaScript ...
Sumit Kumar
Blog Categories
- JavaScript
- Performance
- DSA
- Database
- Security
- Backend