Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 92 of 377

Program to count number of word concatenations are there in the list in python

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

This problem finds how many words in a list are formed by concatenating other words from the same list. We can reuse words multiple times during concatenation. Given the input words = ["hello", "world", "helloworld", "famous", "worldfamous", "programming"], the output is 2 because "helloworld" is formed by concatenating "hello" + "world", and "worldfamous" is formed by "world" + "famous". Algorithm We use a Trie data structure combined with depth-first search (DFS) ? Build a Trie: Store all words in a trie for efficient prefix matching DFS Search: For each ...

Read More

Program to find nearest time by reusing same digits of given time in python

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

Given a 24-hour time string in "hh:mm" format, we need to find the next closest time that can be formed by reusing the same digits. We can reuse any digit from the original time as many times as needed. For example, if the input is "03:15", the output will be "03:30" since it's the nearest valid time using only digits 0, 3, 1, and 5. Algorithm Approach We'll use backtracking to generate all possible valid times using the given digits, then find the next time in chronological order ? Extract all four digits from the ...

Read More

Program to find minimum number of days to wait to make profit in python

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

Suppose we have a list of prices representing the daily stock market prices of a company in chronological sequence. We have to find a same length list where the value at index i will be the minimum number of days we would have to wait until we make a profit. If there is no such way to make a profit, the value should be 0. So, if the input is like prices = [4, 3, 5, 9, 7, 6], then the output will be [2, 1, 1, 0, 0, 0] Algorithm To solve this problem, we will ...

Read More

Program to find all possible strings typed using phone keypad in python

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

Suppose we have a string containing digits from 2-9. We have to find all possible letter combinations that the number could generate. One mapping of digit to letters (just like on the telephone buttons) is given below ? 1 2a b c 3d e f 4g h i 5j k l 6m n o 7p q r s 8t u v 9w x y z * 0 # For example, if the given string is "49", then the possible strings will be ['gw', 'gx', 'gy', 'gz', ...

Read More

Program to check whether a board is valid N queens solution or not in python

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

The N-Queens puzzle is a classic problem where we need to place N queens on an N×N chessboard such that no two queens attack each other. In this article, we'll learn how to verify whether a given board configuration is a valid N-Queens solution. A valid N-Queens solution must satisfy these conditions: Exactly N queens are placed on the board No two queens share the same row, column, or diagonal Understanding the Problem Given an N×N matrix with 1s representing queens and 0s representing empty cells, we need to check if it's a valid N-Queens ...

Read More

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

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 337 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 434 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 155 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
Showing 911–920 of 3,768 articles
« Prev 1 90 91 92 93 94 377 Next »
Advertisements