Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 50 of 377

Program to find number of minimum steps to reach last index in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 598 Views

Suppose we have a list of numbers called nums and we are placed currently at nums[0]. On each step, we can either jump from the current index i to i + 1 or i - 1 or j where nums[i] == nums[j]. We have to find the minimum number of steps required to reach the final index. So, if the input is like nums = [4, 8, 8, 5, 4, 6, 5], then the output will be 3, as we can jump from index 0 to index 4 as their values are both 4. And then we jump back ...

Read More

Program to find number of friend groups in a set of friends connections in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 868 Views

Finding friend groups in a network is a classic graph connectivity problem. We need to count the number of connected components where each person is represented as a node and friendships as edges. This can be solved using Depth-First Search (DFS) to traverse connected friends. Understanding the Problem Given a friends list where friends[i] contains the indices of people that person i is friends with, we need to find how many separate friend groups exist. Two people belong to the same group if there's a path of mutual friendships connecting them. ...

Read More

Program to find maximum sum by flipping each row elements in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 332 Views

Suppose we have a 2D binary matrix. For any row or column in the given matrix we can flip all the bits. If we can perform any number of these operations, and we treat each row as a binary number, we have to find the largest sum that can be made of these numbers. So, if the input is like ? 0 ...

Read More

Campus Bikes II in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 332 Views

The Campus Bikes II problem involves assigning unique bikes to workers on a 2D grid such that the total Manhattan distance is minimized. Given N workers and M bikes (where N ≤ M), we need to find the optimal assignment. The Manhattan distance between two points p1 and p2 is calculated as: |p1.x - p2.x| + |p1.y - p2.y|. Problem Example Given workers = [[0, 0], [2, 1]] and bikes = [[1, 2], [3, 3]]: ...

Read More

Serialize and Deserialize BST in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 631 Views

Serialization converts a binary search tree into a string format that can be stored or transmitted, while deserialization reconstructs the tree from that string. This is useful for saving tree data to files or sending it over networks. Problem Overview Given a binary search tree, we need to serialize it into a string and then deserialize it back to the original tree structure. The serialization uses level-order traversal with dots as separators and 'N' for null nodes. 5 2 ...

Read More

Max Increase to Keep City Skyline in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 344 Views

The Max Increase to Keep City Skyline problem asks us to find the maximum total sum that building heights can be increased while maintaining the original skyline when viewed from all four directions. The skyline from each direction is determined by the maximum height in each row (left/right view) and each column (top/bottom view). Problem Understanding Given a 2D grid where each value represents a building height, we need to ? Calculate the skyline from left/right (maximum in each row) Calculate the skyline from top/bottom (maximum in each column) For each position, the maximum possible height ...

Read More

Design Log Storage System in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 444 Views

A log storage system manages logs with unique IDs and timestamps. Each timestamp follows the format Year:Month:Day:Hour:Minute:Second (e.g., "2019:01:01:23:59:59") with zero-padded decimal numbers. We need to implement two main functions: put(id, timestamp) − Stores a log with its unique ID and timestamp retrieve(start, end, granularity) − Returns log IDs within a time range based on specified granularity (Year, Month, Day, Hour, Minute, Second) How Granularity Works The granularity parameter determines the precision level for comparison. For example, with granularity "Day", timestamps are compared only up to the day level, ignoring hours, minutes, and seconds. ...

Read More

Program to find airports in correct order in Python?

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 418 Views

Finding airports in correct order from a shuffled list of flights is a classic graph traversal problem. We need to reconstruct the travel itinerary by finding an Eulerian path through the flight connections, ensuring lexicographical ordering when multiple valid paths exist. Algorithm Overview The solution uses Hierholzer's algorithm to find an Eulerian path in a directed graph ? Build adjacency list from flight pairs Track in-degree and out-degree for each airport Find starting airport (out-degree - in-degree = 1, or lexicographically smallest) Use DFS to traverse and build the path Return reversed path for correct order ...

Read More

Program to check whether we can make k palindromes from given string characters or not in Python?

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 253 Views

Suppose we have a string s and another number k, we have to check whether we can create k palindromes using all characters in s or not. So, if the input is like s = "amledavmel" k = 2, then the output will be True, as we can make "level" and "madam". Algorithm To solve this, we will follow these steps − d := a map where store each unique characters and their frequency cnt := 0 for each key in d, do if d[key] is odd, then cnt := cnt + 1 ...

Read More

Program to find minimum number of Fibonacci numbers to add up to n in Python?

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 405 Views

Suppose we have a number n; we have to find the minimum number of Fibonacci numbers required to add up to n. This problem uses a greedy approach where we always pick the largest possible Fibonacci number. So, if the input is like n = 20, then the output will be 3, as we can use the Fibonacci numbers [2, 5, 13] to sum to 20. Algorithm To solve this, we will follow these steps − Initialize result counter to 0 Generate Fibonacci numbers up to n ...

Read More
Showing 491–500 of 3,768 articles
« Prev 1 48 49 50 51 52 377 Next »
Advertisements