Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 43 of 377

Program to check whether we can unlock all rooms or not in python

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

Suppose we have a list of lists called rooms. Each index i in rooms represents a room and rooms[i] represents different keys to open other rooms. Room 0 is open and we start there, while every other room is locked. We can move freely between opened rooms — we need to check whether we can open every room or not. So, if the input is like rooms = [[2, 0], [3], [1], []], then the output will be True. We start from room 0 and can go to room 2 with its key 2. From room 2 we can ...

Read More

Program to check whether given list of blocks are symmetric over x = y line or not in python

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

Suppose we have a list of numbers called nums representing the height of square blocks. We need to check whether the shape is symmetric over the y = x line (diagonal reflection). For a shape to be symmetric over the y = x line, when we reflect it diagonally, the resulting shape should be identical to the original. Problem Understanding Given nums = [7, 5, 3, 2, 2, 1, 1], we need to verify if this block arrangement is symmetric over the y = x line. ...

Read More

Program to sort a given linked list into ascending order in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 5K+ Views

Suppose we have a linked list. We have to sort the list into ascending order using Python. So, if the input is like [5, 8, 4, 1, 5, 6, 3], then the output will be [1, 3, 4, 5, 5, 6, 8] Algorithm To solve this, we will follow these steps − Extract all values from the linked list into a Python list Sort the extracted values using built-in sort() method Traverse the original linked list again and replace node values with sorted ...

Read More

Program to find number of items left after selling n items in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 3K+ Views

Suppose we have a list of numbers called items and another value n. A salesman has items in a bag with random IDs. The salesman can remove as many as n items from the bag. We have to find the minimum number of different IDs remaining in the bag after n removals. The strategy is to remove items with the lowest frequencies first, as this minimizes the number of different IDs left. Example If the input is like items = [2, 2, 6, 6] and n = 2, then the output will be 1. We can sell ...

Read More

Program to check whether leaves sequences are same of two leaves or not in python

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

In this problem, we need to check whether two binary trees have the same sequence of leaf nodes when read from left to right. A leaf node is a node that has no left or right children. So, if the input trees are: Tree 1 1 3 2 6 ...

Read More

Program to reverse words separated by set of delimiters in python

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

Sometimes we need to reverse words in a string while keeping delimiters in their original positions. This is useful when processing formatted text where the structure must be preserved but the word order needs to be reversed. So, if the input is like s = "Computer/Network:Internet|tutorialspoint" with delimiters ["/", ":", "|"], then the output will be tutorialspoint/Internet:Network|Computer. Algorithm To solve this problem, we follow these steps ? Extract all words (non-delimiter characters) and store them in a list Iterate through the original string character by character If the character is a delimiter, add it directly ...

Read More

Program to reverse inner nodes of a linked list in python

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

Given a linked list and two positions i and j, we need to reverse the nodes from position i to position j (0-indexed). The rest of the nodes remain in their original positions. For example, if we have a linked list [1, 2, 3, 4, 5, 6, 7, 8, 9] with i = 2 and j = 6, the output will be [1, 2, 7, 6, 5, 4, 3, 8, 9]. Algorithm To solve this problem, we follow these steps: Create a dummy head node pointing to the original head Traverse to find the node ...

Read More

Program to evaluate ternary expression in C++

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

Looking at this article, I can see it's about C++ but labeled as Python. I'll improve the structure, fix the HTML issues, and make it clearer while keeping the C++ content intact. A ternary expression uses the format condition ? value1 : value2. Given a string representing nested ternary expressions with 'T' (True) and 'F' (False), we need to evaluate the final result. Problem Constraints String length ≤ 10000 Conditional expressions group right-to-left Conditions are always 'T' or 'F', never digits Final result is always 'T' or 'F' For example, "T?T?F:T:T" evaluates to "F". ...

Read More

Program to check we can update a list index by its current sum to reach target or not in python

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

Suppose we have a list of numbers called target. We start with a list X of the same length filled with 1s. We can perform the following operation repeatedly: select any index i in X and set X[i] to the current sum of all elements in X. The goal is to check whether X can be transformed into the target list. For example, if target = [5, 9, 3], we start with X = [1, 1, 1] (sum = 3). Update index 2: X = [1, 1, 3] (sum = 5). Update index 0: X = [5, 1, 3] ...

Read More

Program to convert gray code for a given number in python

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

Gray code is a binary numeral system where consecutive numbers differ by exactly one bit. For example, the gray code sequence starts as: 000, 001, 011, 010, 110, 111, 101, 100. Given a number n, we need to find the nth gray code in decimal representation. The key insight is that gray codes follow a recursive pattern where we can find the nth gray code by determining the highest power of 2 less than or equal to n, then recursively solving for the remaining part. Algorithm Steps To convert a number to its corresponding gray code position: ...

Read More
Showing 421–430 of 3,768 articles
« Prev 1 41 42 43 44 45 377 Next »
Advertisements