Aditya Chatterjee's Blog, page 149

October 31, 2021

Number of Islands in MxN matrix (of 0 and 1)

In this article, we have explored an insightful approach/ algorithm to find the number of islands in MxN matrix. An extension of this algorithm is used by online battleship game engine.

TABLE OF CONTENTSPROBLEM STATEMENT DEFINITIONPROBLEM ANALYSISSOLUTION ANALYSISMETHOD-1 BREADTH-FIRST-SEARCH APPROACHAlgorithmImplementationComplexityMETHOD-2 DEPTH-FIRST-SEARCH WHILE UPDATING MATRIX APPROACHAlgorithmImplementationComplexityMETHOD-3 DEPTH-FIRST-SEARCH WHILE UPDATING MATRIX APPRO...
 •  0 comments  •  flag
Share on Twitter
Published on October 31, 2021 03:49

Error Handling in Rust

Let's tackle 2 topics today. One of them is about dealing with possible errors and/or mistakes we might encounter in our developing journey in Rust. The other is about learning how to write code with these in mind.

Table of contents:

Error HandlingTo panic! or not to panic!ResultUnwrap and ExpectError Propagating

Let us get started with Error Handling in Rust.

Error handling

Errors will happen. There's no way around it. Even the best programmers out there make mistakes. The more you make a...

 •  0 comments  •  flag
Share on Twitter
Published on October 31, 2021 02:11

Web Sockets (ws:// , wss://)

Web Sockets (ws:// , wss://)

In this article, we will talk about webockets, it's a very important and fundamental topic for anyone interested in web and communication protocols. WebSocket is a computer communication protocol, providing full connections over a single TCP connection.

Table of contents:

How HTTP works? (http:// , https://)How does websocket work? (ws:// , wss://)When to use websockets?Pros of using websocketsCons of using websocketsImplementing a websocket in PythonPopular WebSocket librariesConclusion...
 •  0 comments  •  flag
Share on Twitter
Published on October 31, 2021 00:48

October 29, 2021

Flood Fill Algorithms

Welcome to OpenGenus 🎉,

Today, I will be discussing a very easy and perhaps the most beautiful algorithm that is the "Flood Fill Algorithms".

Flood Fill algorithm is an Algorithm that determines the area connected to a given node in a N-dimensional array. Some operations are performed on the connected nodes like color change. This is also known as Seed Fill Algorithm.

The idea is that you are given a N-dimensional space and some nodes are blocked with stones. One node is the source of water and ...

 •  0 comments  •  flag
Share on Twitter
Published on October 29, 2021 22:10

Merge K sorted Linked Lists

We have explained 3 different algorithms to Merge K sorted Linked Lists such that the final Linked List is also sorted.

Table of contents:

Introduction / Problem StatementMethod 1Method 2Method 3Applications

Prerequisite: Linked List, Sorting Algorithm

This is similar to Leetcode Problem 23. Merge k Sorted Lists. Let us get started with Merge K sorted Linked Lists.

Introduction / Problem Statement

In this problem, we are given 'k' number of linked lists. All these lists have already been s...

 •  0 comments  •  flag
Share on Twitter
Published on October 29, 2021 20:16

K-th permutation of first N integers

In this article, we will understand and explore about the concept of generating k-th lexicographical permutation of first N integers. There are O(N!) permutations but you can find it in O(N) time.

Table of contentsPermutation sequencekth permutation of first n integersComplexity analysis

This is similar to Leetcode problem 60. Permutation Sequence. Let us get started with this problem.

Permutation Sequence

Literally, permutation is the arrangement of objects in a definite order. Mathematica...

 •  0 comments  •  flag
Share on Twitter
Published on October 29, 2021 17:39

2 Sum Closest: Find 2 elements with sum closest to target

We have explained how to solve the 2 Sum Closest problem that is Find 2 elements with sum closest to a target efficiently. We have explained 3 different approaches which involves the use of Binary Search and Two Pointer technique.

Table of ContentsIntroductionApproach 1 - Brute ForceApproach 2 - Binary SearchApproach 3 - Two PointersOverview

Prerequisites: Two Pointer Technique, Binary Search

Introduction

In this article we will cover the basis of the 2 sum closest problem and different a...

 •  0 comments  •  flag
Share on Twitter
Published on October 29, 2021 16:37

Logical Reasoning Questions for Coding Interview

These Logical Reasoning Questions are designed for Coding Interviews at Companies hiring for Software Development or Engineering roles (Full-time + Intern). These questions are frequently asked at Amazon, Microsoft and other companies. These are usually asked in the first round of Interview.

The questions are of Increasing Difficulty. Practice all questions.

Q1. Consider the following sequence: 10, 14, 12, 16, 14, 18, 16, 20, ...
What is the next number is the sequence?18222416The next ...
 •  0 comments  •  flag
Share on Twitter
Published on October 29, 2021 12:05

Behavioral Questions for Coding Interviews

We have presented the most common Behavioral Questions for Coding Interviews. These are asked in the final Interview at companies like Google and Amazon for the role of SDE (full-time + Intern).

These questions are asked in the final Interview once you have cleared all technical interviews. This is an important round as many take it lightly and fail. This Interview is taken by a Team Manager of the team you are supposed to join. Team Manager is a senior person with 10+ years of experience.

You w...

 •  0 comments  •  flag
Share on Twitter
Published on October 29, 2021 10:57

October 28, 2021

Ownership, Borrowing and Lifetimes in Rust

One of the key elements Rust has, which is also considered it's most unique feature, is the Ownership model. This allows memory safe operations without a garbage collector, and completely avoids (if using safe rust), some of the big problems other languages run into when it comes to memory management.

Table of contents:

OwnershipReferences and BorrowingLifetimes

Let us get started with Ownership, Borrowing and Lifetimes in Rust.

What is Ownership?

Ownership is pretty easy to explain conceptu...

 •  0 comments  •  flag
Share on Twitter
Published on October 28, 2021 02:05