Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 118 of 377

Program to find length of contiguous strictly increasing sublist in Python

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

Suppose we have a list of numbers called nums, we have to find the maximum length of a contiguous strictly increasing sublist when we can remove one or zero elements from the list. So, if the input is like nums = [30, 11, 12, 13, 14, 15, 18, 17, 32], then the output will be 7, as when we remove 18 in the list we can get [11, 12, 13, 14, 15, 17, 32] which is the longest, contiguous, strictly increasing sublist, and its length is 7. Algorithm To solve this, we will follow these steps − ...

Read More

Program to find length of substring with consecutive common characters in Python

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

Finding the length of the longest substring with consecutive identical characters is a common string processing problem. We need to iterate through the string and track the maximum count of consecutive characters. Problem Statement Given a string, find the length of the longest substring containing the same consecutive characters. For example, in the string "abbbaccabbbba", the longest substring with consecutive identical characters is "bbbb" with length 4. Algorithm The approach involves iterating through the string and maintaining two counters ? Track the current consecutive character count Track the maximum consecutive count seen so far ...

Read More

Program to replace each element by smallest term at left side in Python

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

Suppose we have a list of numbers called nums, we have to replace every nums[i] with the smallest element left of i. We have to replace nums[0] with 0. So, if the input is like [15, 7, 9, 16, 12, 25], then the output will be [0, 15, 7, 7, 7, 7]. Algorithm To solve this, we will follow these steps − If nums is empty, then return a new ...

Read More

Program to make all elements equal by performing given operation in Python

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

Suppose we have a list of numbers and we want to make all values equal. We can perform an operation where we pick one element from the list and increment every other element by 1. We need to find the minimum number of operations required to make all element values equal. So, if the input is like [2, 4, 5], then the output will be 5. Algorithm To solve this problem, we will follow these steps − Find the minimum value in the list Initialize sum as 0 ...

Read More

Program to perform given operation with each element of a list and given value in Python

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

Suppose we have a list of numbers called nums, an operator string op representing operations like "+", "-", "/", or "*", and a value val. We need to perform the operation on every number in nums with val and return the result. For example, if the input is [5, 3, 8] with operator "*" and value 3, the output will be [15, 9, 24]. Algorithm Steps To solve this problem, we will follow these steps − Create an empty result list For each number in the input list: ...

Read More

Program to remove all nodes of a linked list whose value is same as in Python

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

A singly linked list is a linear data structure where each node contains data and a reference to the next node. Sometimes we need to remove all nodes with a specific target value while maintaining the list structure. So, if the input is like [5, 8, 2, 6, 5, 2, 9, 6, 2, 4] and target is 2, then the output will be [5, 8, 6, 5, 9, 6, 4]. Algorithm To solve this problem, we follow these steps − Start with the head node While current node and next node exist: If next ...

Read More

Program to check whether a binary tree is BST or not in Python

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

A Binary Search Tree (BST) is a binary tree with specific ordering properties. We can check if a binary tree is a valid BST by performing an inorder traversal and verifying the result is sorted. BST Properties A valid BST must satisfy these conditions − All nodes in the left subtree are smaller than the current node value All nodes in the right subtree are larger than the current node value These properties hold recursively for all nodes ...

Read More

Program to remove all nodes from BST which are not in range in Python

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

In this tutorial, we'll learn how to remove all nodes from a Binary Search Tree (BST) that are not within a given range [low, high]. This is a common tree pruning problem that uses the BST property to efficiently eliminate nodes. Problem Statement Given a BST and two values low and high, we need to delete all nodes that are not between [low, high] (inclusive). The resulting tree should maintain the BST property. Original BST 5 1 9 ...

Read More

Program to check whether different brackets are balanced and well-formed or not in Python

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

Checking whether brackets are balanced is a classic programming problem. A string of brackets is considered balanced when every opening bracket has a corresponding closing bracket in the correct order. For example, the string "([()()]{[]})()" is balanced because each opening bracket matches with its corresponding closing bracket properly. Algorithm Approach We use a stack data structure to solve this problem efficiently ? Create an empty stack to store opening brackets Create a dictionary mapping each closing bracket to its opening counterpart For each character in the string: If it's a closing bracket, check if ...

Read More

Program to check whether parentheses are balanced or not in Python

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

Checking whether parentheses are balanced is a fundamental programming problem. A string has balanced parentheses if every opening parenthesis ( has a corresponding closing parenthesis ) and they appear in the correct order. So, if the input is like s = "(()())(())", then the output will be True because all parentheses are properly matched. Algorithm Approach To solve this problem, we will follow these steps − Initialize a counter open_count to track open parentheses For each character in the string: ...

Read More
Showing 1171–1180 of 3,768 articles
« Prev 1 116 117 118 119 120 377 Next »
Advertisements