Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 91 of 377

Program to find the size of the longest sublist where car speed is constant in python

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

Suppose we have a list of numbers representing the position of a car at equally spaced intervals of time. We have to find the size of the longest sublist where the car was traveling at a constant speed. So, if the input is like positions = [0, 4, 8, 12, 6, 4, 0], then the output will be 4, as the sublist is [0, 4, 8, 12]. Algorithm To solve this, we will follow these steps − j := 1 max_cnt := 0, current := 0 ...

Read More

Program to check given push pop sequences are proper or not in python

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

When working with stack operations, we often need to validate whether a given sequence of push and pop operations is possible. This problem involves checking if two sequences represent valid stack push and pop actions. Given two lists pushes and pops, we need to determine if we can simulate the push operations in order while achieving the exact pop sequence specified. Example Scenario If we have pushes = [1, 2, 5, 7, 9] and pops = [2, 1, 9, 7, 5], this is valid because we can: Push 1, then push 2, then pop 2, ...

Read More

Program to find number of square submatrices with 1 in python

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

Suppose we have a 2D binary matrix, we have to find the total number of square submatrices with all 1s. This problem can be solved using dynamic programming by tracking the largest square ending at each position. So, if the input is like: 1 ...

Read More

Program to find final states of rockets after collision in python

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

We have a list of numbers representing rocket sizes and directions. Positive integers indicate rightward movement, negative numbers indicate leftward movement. The absolute value represents the rocket's size. When rockets collide, the smaller one is destroyed, and equal-sized rockets both get destroyed. Problem Understanding Given rockets moving in opposite directions, we need to simulate collisions and find the final state. Rockets moving in the same direction never collide. Example For nums = [3, 8, 5, -5], rockets 5 (right) and -5 (left) collide and both are destroyed, leaving [3, 8]. Algorithm We'll use a ...

Read More

Program to find minimum space plane required for skydivers in k days in python

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

Suppose we have a list of numbers called nums where each value represents a group of people looking to skydive together. And we have another value k representing how many days they can apply for skydiving. We have to find the minimum capacity of the plane we need to be able to fulfill all requests within k days. The requests should be fulfilled in the order they were given and a plane can only fly once a day. So, if the input is like nums = [16, 12, 18, 11, 13], k = 3, then the output will be ...

Read More

Program to find shortest cycle length holding target in python

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

Finding the shortest cycle containing a specific target node in a directed graph is a common graph problem. We can solve this using Breadth-First Search (BFS) to explore paths from the target node until we find a cycle back to it. Problem Understanding Given an adjacency list representation of a directed graph and a target node, we need to find the shortest cycle that contains the target node. If no such cycle exists, return -1. ...

Read More

Program to find total cost for completing all shipments in python

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

We need to find the total cost for completing all shipments between ports, where the cost is the shortest path distance between each pair of ports. This problem uses the Floyd-Warshall algorithm to find all shortest paths in a graph. Problem Understanding Given a list of ports where ports[i] represents connected ports from port i, and shipments as pairs [i, j], we need to find the minimum total cost. Each edge has weight 1, so the cost is the shortest path length. For the example: ports = [[1, 4], [2], [3], [0, 1]], shipments = [[1, 4]], ...

Read More

Program to convert a string to zigzag string of line count k in python

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

The zigzag string conversion arranges characters in a zigzag pattern across k lines. Starting from the top line, we move diagonally down until reaching the bottom (kth line), then move diagonally up back to the top, and repeat this pattern. For example, if the input is s = "ilovepythonprogramming" and k = 5, the zigzag pattern looks like this: i h r l t o a o y ...

Read More

Program to find length of longest alternating path of a binary tree in python

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

Suppose we have a binary tree, we have to find the longest path that alternates between left and right child and going down. An alternating path means we switch between going left and right at each level. So, if the input is like ? 2 3 4 5 ...

Read More

Program to find length of longest word that can be formed from given letters in python

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

Suppose we have a list of words and a string called letters, we have to find the size of the longest word that can be made by rearranging the given letters. In the letters there may be asterisk character (*) which can match any character. It is not necessary to use all the letters. So, if the input is like words = ["prince", "rice", "price", "limit", "hello"] letters = "*r**ce*", then the output will be 6, as the longest word we can make is "prince" with length 6. Algorithm To solve this, we will follow these steps ...

Read More
Showing 901–910 of 3,768 articles
« Prev 1 89 90 91 92 93 377 Next »
Advertisements