Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 55 of 377

Boundary of Binary Tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 288 Views

Suppose we have a binary tree, we have to find the values of its boundary in anti-clockwise direction starting from root. Here boundary includes left boundary, leaves, and the right boundary in order without duplicate nodes.The left boundary is the path from root to the left-most node.The Right boundary is the path from root to the right-most node.When the root doesn't have left subtree or right subtree, then the root itself is left boundary or right boundary.So, if the input is likethen the output will be [1, 2, 4, 7, 8, 9, 10, 6, 3]To solve this, we will follow ...

Read More

Program to find maximum number of boxes we can fit inside another boxes in python

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

Suppose we have a list of boxes where each row represents the height and width of given boxes. We can put a box in another box if first box is smaller than the second one (when both of its width and height are smaller than the other box), we have to find the maximum number of boxes we can fit into a box.So, if the input is likeWidthHeight1212101066510then the output will be 3, as we can fit the box [6, 6] inside [10, 10] which we can be put into [12, 12] box.To solve this, we will follow these steps ...

Read More

Split Array with Equal Sum in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 915 Views

Suppose we have an array with n integers, we have to find if there are triplets (i, j, k) which follows these conditions −0 < i, i + 1 < j, j + 1 < k < n - 1Sum of subarrays (0, i - 1), (i + 1, j - 1), (j + 1, k - 1) and (k + 1, n - 1) will be same.The subarray (L, R) is a slice of the original array starting from the element indexed L to the element indexed R.So, if the input is like [1, 2, 1, 2, 1, 2, ...

Read More

Program to check a string can be broken into given list of words or not in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 637 Views

Suppose we have a word list and another string s with no spaces. We have to check whether the string can be broken down using the list of words or not.So, if the input is like words = ["love", "python", "we", "programming", "language"] s = "welovepythonprogramming", then the output will be TrueTo solve this, we will follow these steps −words := a new set of all unique wordsDefine a function rec() . This will take iif i is same as size of s , thenreturn Trueacc := blank stringfor j in range i to size of s, doacc := acc ...

Read More

Program to find maximum profit after buying and selling stocks at most two times in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 323 Views

Suppose we have a list of numbers called prices and that is representing the stock prices of a company in chronological order, we have to find the maximum profit we can make from buying and selling that stock at most two times. We have to buy first then sell.So, if the input is like prices = [2, 6, 3, 4, 2, 9], then the output will be 11, as we can buy at price 2, then sell at 6, again buy at 2, and sell at 9.To solve this, we will follow these steps −first_buy := -inf, first_sell := -infsecond_buy ...

Read More

Split Concatenated Strings in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 619 Views

Suppose we have a list of strings, we can concatenate these strings together into a loop, where for each string we can choose to reverse it or not. Among all of the possible loops, we need to find the lexicographically largest string after cutting the loop, which will make the looped string into a regular one. Specifically, to find the lexicographically largest string, we need to experience two phases −Concatenate all the strings into one loop, where we can reverse some strings or not and connect them in the same order as given.Cut and make one cutting point in any ...

Read More

Program to find minimum cost to reach final index with at most k steps in python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 284 Views

Suppose we have a list of numbers nums and another value k. Here the items at nums[i] represents the costs of landing at index i. If we start from index 0 and end at the last index of nums. In each step we can jump from some position X to any position up to k steps away. We have to minimize the sum of costs to reach last index, so what will be the minimum sum?So, if the input is like nums = [2, 3, 4, 5, 6] k = 2, then the output will be 12, as we can ...

Read More

Longest Line of Consecutive One in Matrix in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 410 Views

Suppose we have one binary matrix M, we have to find the longest line of consecutive one in that matrix. The line could be horizontal, vertical, diagonal or anti-diagonal.So, if the input is like011001100001then the output will be 3To solve this, we will follow these steps −ret := 0n := row of Mm := column of MDefine one 3D array dp of order n x m x 4for initialize i := 0, when i < m, update (increase i by 1), do −for initialize j := 0, when j < 4, update (increase j by 1), do −dp[0, i, j] ...

Read More

Squirrel Simulation in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 401 Views

There's a tree, a squirrel, and several nuts. Positions are represented by the cells in a 2D grid. Your goal is to find the minimal distance for the squirrel to collect all the nuts and put them under the tree one by one. The squirrel can only take at most one nut at one time and can move in four directions - up, down, left, and right, to the adjacent cell. The distance is represented by the number of moves.So, if the input is like Height: 5 Width: 7 Tree position: [2, 2] Squirrel: [4, 4] Nuts: [[3, 0], [2, ...

Read More

Kill Process in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose we have n processes, here each process has a unique id called PID or process id and its PPID (parent process id) is also there.Each process only has one parent process, but may have one or more child processes.This is just like a tree structure. Only one process has the PPID = 0, which means this process has no parent process. All the PIDs will be unique positive integers.We will use two list of integers to represent a list of processes, where the first list contains PID for each process and the second list contains the corresponding PPID. So, ...

Read More
Showing 541–550 of 3,768 articles
« Prev 1 53 54 55 56 57 377 Next »
Advertisements