Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 162 of 377

Linked List in Binary Tree in C++

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

Suppose we have a binary tree root and a linked list with a head as the first node. We have to return True if all the elements in the linked list starting from the head correspond to some downward path connected in the binary tree otherwise False. So if the tree is like −And the linked list is [1, 4, 2, 6], then the output will be true.To solve this, we will follow these steps −Define a map dpDefine a method called solve(), this will take head, root, and flagif the head is null, then return true, or if the ...

Read More

Partition Array for Maximum Sum in Python

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

Suppose we have an integer array A, we have to partition the array into (contiguous) subarrays of length at most K. After partitioning, each subarray has their values changed to become the maximum value of that subarray. We have to find the largest sum of the given array after partitioning. So if input is like [1, 15, 7, 9, 2, 5, 10] and k = 3, then the output will be 84. This is because the array becomes [15, 15, 15, 9, 10, 10, 10]To solve this, we will follow these steps −make one array dp of length same as ...

Read More

Find the Longest Substring Containing Vowels in Even Counts in C++

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

Suppose we have the string s, we have to find the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times. So if the string is like “helloworld”, then the output will be 8.To solve this, we will follow these steps −ret := 0, define two maps m and cnt, set m[“00000”] := -1store vowels into vowels arrayfor i in range 0 to size of sx := s[i], and ok := falseincrease cnt[x] by 1, set temp := empty stringfor k in ...

Read More

Previous Permutation With One Swap in Python

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

Suppose we have an array A of positive integers (not necessarily unique), we have to find the lexicographically largest permutation that is smaller than A, that can be made with one swap (A swap exchanges the positions of two numbers A[i] and A[j]). If it cannot possible, then return the same array. So if the array is like [3, 2, 1], then the output will be [3, 1, 2], by swapping 2 and 1To solve this, we will follow these steps −n := size of Afor left in range n – 2 down to -1if left = -1, then return ...

Read More

Distant Barcodes in Python

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

Suppose in a warehouse, there is a row of barcodes. The i-th barcode is barcodes[i]. We have to rearrange the barcodes so that no two adjacent barcodes are same. So if the input is [1, 1, 1, 2, 2, 2] so output is [2, 1, 2, 1, 2, 1].To solve this, we will follow these steps −make one map named dstore the frequency of numbers present in the barcode array into dx := empty listinsert all key-value pairs into xi := 0res := make a list whose length is same as barcodes, and fill [0]sort x based on the frequencywhile ...

Read More

Longest ZigZag Path in a Binary Tree in C++

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

Suppose we have a binary tree root, a ZigZag path for a binary tree is defined as follow −Choose any node in the binary tree and a direction (either right or left).If the current direction is right then moving towards the right child of the current node otherwise move towards the left child.Then change the direction from right to left or vice versa.Repeat the second and third steps until we can't move in the tree.Here the Zigzag length is defined as the number of nodes visited - 1. (A single node has a length of 0). We have to find ...

Read More

Flip Columns For Maximum Number of Equal Rows in Python

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

Suppose we have a matrix consisting of 0s and 1s, we can choose any number of columns in the matrix and flip every cell in that column. converting a cell changes the value of that cell from 0 to 1 or from 1 to 0. we have to find the maximum number of rows that have all values equal after some number of flips. So if the matrix is like −000001110The output will be 2. This is because after converting values in the first two columns, the last two rows have equal values.To solve this, we will follow these steps ...

Read More

Letter Tile Possibilities in Python

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

Suppose we have a set of tiles, where each tile has one letter tiles[i] printed on it. Find the number of possible non-empty sequences of letters that we can make. So if the input is “AAB”, then the output will be 8. As sequences are “A”, “B”, “AA”, “AB”, “BA”, “AAB”, “ABA”, “BAA”To solve this, we will follow these steps −Define one dfs(), that will take countsum := 0for i in range 1 to 26if count[i] = 0, then go for next iteration, without checking the restdecrease count[i] by 1, and increase sum by 1sum := sum + dfs(count)increase count[i] ...

Read More

Bulb Switcher III in C++

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

Suppose we have a room with n bulbs, these are numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off. At moment k (for k in range 0 to n - 1), we turn on the light[k] bulb. A bulb changes color to blue only if it is on and all the previous bulbs (to the left) are turned on too. We have to find the number of moments in which all turned on bulbs is blue. So this is an example −The output will be 3 as the moments ...

Read More

Score After Flipping Matrix in C++

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

Suppose we have a two dimensional matrix A where each value is 0 or 1. Here a move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s. Now after making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers. So our task is to find the highest possible score. If the input is like −001110101100The output will be 39 as after toggling, the matrix will ...

Read More
Showing 1611–1620 of 3,768 articles
« Prev 1 160 161 162 163 164 377 Next »
Advertisements