Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 177 of 377

Minimum Remove to Make Valid Parentheses in C++

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

Suppose we have a string s of '(' , ')' and lowercase English characters. We have to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parenthese string is valid and return any valid string. A parentheses string is valid when all of these criteria are fulfilled −It is the empty string, contains lowercase characters only, orIt can be written as the form of AB (A concatenated with B), where A and B are valid strings, orIt can be written as the form of (A), where A is a valid string.So ...

Read More

Find the Smallest Divisor Given a Threshold in C++

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

Suppose we have an array of integers called nums and an integer k, that is threshold value, we will choose a positive integer divisor and divide all the array by it and sum the result of the division. We have to find the smallest divisor such that the result mentioned above is less than or equal to threshold value k. For example − if nums = [1, 2, 5, 9] and k = 6, then the output will be 5. We can get the sum as (1+2+5+9) = 17 when the divisor is 1. If the divisor is 4, then ...

Read More

Sequential Digits in C++

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

Suppose we have an integer, that has sequential digits if and only if each digit in the number is one more than the previous digit. We have to find a sorted list of all the integers in the range [low, high] inclusive that have sequential digits. So if the low = 100 and high = 300, then the output will be [123,234]To solve this, we will follow these steps −create one array resfor i in range 1 to nfor j := 1, until j + i – 1

Read More

Find Elements in a Contaminated Binary Tree in C++

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

Suppose we have a binary tree. The rules of that tree is as follows −root.val == 0If treeNode.val is x and treeNode.left is not null, then treeNode.left.val = 2 * x + 1If treeNode.val is x and treeNode.right is not null, then treeNode.right.val = 2 * x + 2Now as the binary tree is contaminated. This indicates all val of the tree node have been changed to -1. We have to first recover the binary tree and then implement the FindElements class as follows −FindElements(TreeNode* root) Initializes the object with a contamined binary tree, we have to recover it first.bool ...

Read More

Divide Array in Sets of K Consecutive Numbers in C++

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

Suppose we have an array of integers nums and a positive integer k, we have to find whether it's possible to divide this array into sets of k consecutive numbers. So we have to return True if its possible otherwise return False. So if the input is like [1, 2, 3, 3, 4, 4, 5, 6] and k = 4, then output will be true. This is because, we can divide the array such that [1, 2, 3, 4] and [3, 4, 5, 6]To solve this, we will follow these steps −Make one map m, set n := size of ...

Read More

Largest Number in Python

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

Suppose there is a list of non-negative integers, we have to arrange them such that they form the largest number. So if the array is [10, 2], then the largest number will be 210.To solve this, we will follow these steps −Arrange the numbers where the most significant digits are greater than place them at first, like this arrangement the numbers. After that just join the numbers from the array.ExampleLet us see the following implementation to get a better understanding −from functools import cmp_to_key class Solution(object):    def largestNumber(self, nums):       for i in range(len(nums)):       ...

Read More

Search Suggestions System in C++

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

Suppose we have an array of strings products and a string called searchWord. We want to design a module that suggests at most three product names from products list after each character of searchWord is typed. The suggested products should have common prefix with the searchWord. When there are more than three products with a common prefix return the three lexicographically minimums products. So we have to find the lists of the suggested products after each character of searchWord is typed.If the input is like: [ "mobile", "mouse", "moneypot", "monitor", "mousepad"], and the searchWord is “mouse”, then the output will ...

Read More

Sum of Mutated Array Closest to Target in C++

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

Suppose we have an integer array arr and a target value target, we have to find the integer value such that when we change all the integers larger than value in the given array will be equal to value, the sum of the array gets as nearest as possible to target. If they are same, then return the minimum such integer. So if the array is like [4, 9, 3] and target is 10, then the output will be 3 as using 3, the array will be [3, 3, 3], so the sum is 9, that is nearest element to ...

Read More

Bulb Switcher in C++

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

Suppose there are n bulbs that are initially switched off. We first turn on all the bulbs. Then, we turn off every second bulb. On the third round, we toggle every third bulb (turning on if it's off or turning off if it's on). Similarly, for the i-th round, we toggle every i bulb. For the n-th round, we only toggle the last bulb. So we have to find how many bulbs are on after n rounds. So if the input is 3, then the result will be 1. This is because −At first, the three bulbs are [off, off, ...

Read More

Valid Parenthesis String in C++

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

Suppose we have an expression. The expression has some parentheses; we have to check the parentheses are balanced or not. The order of the parentheses are (), {} and []. Suppose there are two strings. “()[(){()}]” this is valid, but “{[}]” is invalid.To solve this, we will follow these steps −Traverse through the expression until it has exhaustedif the current character is opening bracket like (, { or [, then push into stackif the current character is closing bracket like ), } or ], then pop from stack, andcheck whether the popped bracket is corresponding starting bracket of thecurrent character, ...

Read More
Showing 1761–1770 of 3,768 articles
« Prev 1 175 176 177 178 179 377 Next »
Advertisements